GitHub PullRequestReviewCommentEvent at 2014-04-09 18:54:55
Repository: watson
Actor: houndci
Payload: {"comment":{"url":"https://api.github.com/repos/strudelfish/watson/pulls/comments/11452366","id":11452366,"diff_hunk":"@@ -0,0 +1,612 @@\n+module Watson\n+  # Command line parser class\n+  # Controls program flow and parses options given by command line\n+  class Command\n+\n+    class << self\n+\n+    # Include for debug_print\n+    include Watson\n+\n+\n+    ###########################################################\n+    # Command line controller\n+    # Manages program flow from given command line arguments\n+    def execute(*args)\n+    # [review] - Should command line args append or overwrite config/RC parameters?\n+    #        Currently we overwrite, maybe add flag to overwrite or not?\n+\n+      # Identify method entry\n+      debug_print \"#{ self } : #{ __method__ }\\n\"\n+\n+      # List of possible flags, used later in parsing and for user reference\n+      _flag_list = %w[\n+        -c --context-depth\n+        -d --dirs\n+        --debug\n+        -f --files\n+        --format\n+        -h --help\n+        -i --ignore\n+        -p --parse-depth\n+        -r --remote\n+        -s --show\n+        -t --tags\n+        -u --update\n+        -v --version\n+      ]\n+\n+      # Add debug prints based on --debug flag\n+      if (_index = args.index('--debug')) != nil\n+        _debug_mode = Array.new\n+        _index += 1\n+        until _flag_list.include?(args[_index]) ||  _index > (args.length - 1)\n+          _debug_mode.push(args[_index].downcase)\n+          _index += 1\n+        end\n+        # Slice out so we can ignore in regular CLI parsing\n+        args.slice!(args.index('--debug') ... _index)\n+\n+        Watson.debug_mode = _debug_mode\n+      end\n+\n+\n+      # If we get the version or help flag, ignore all other flags\n+      # Just display these and exit\n+      # Using .index instead of .include? to stay consistent with other checks\n+      return help         if args.index('-h') != nil  || args.index('--help')    != nil\n+      return version      if args.index('-v') != nil  || args.index('--version') != nil\n+\n+\n+      # If not one of the above then we are performing actual watson stuff\n+      # Create all the necessary watson components so we can perform\n+      # all actions associated with command line args\n+\n+\n+      # Only create Config, don't call run method\n+      # Populate Config parameters from CL THEN call run to fill in gaps from RC\n+      # Saves some messy checking and sorting/organizing of parameters\n+      @config   = Watson::Config.new\n+      @parser   = Watson::Parser.new(@config)\n+      @printer  = Watson::Printer.new(@config)\n+\n+      # Capture Ctrl+C interrupt for clean exit\n+      # [review] - Not sure this is the correct place to put the Ctrl+C capture\n+      trap(\"INT\") do\n+        File.delete(@config.tmp_file) if File.exists?(@config.tmp_file)\n+        exit 2\n+      end\n+\n+      # Parse command line options\n+      # Begin by slicing off until we reach a valid flag\n+\n+      # Always look at first array element in case and then slice off what we need\n+      # Accept parameters to be added / overwritten if called twice\n+      # Slice out from argument until next argument\n+\n+      # Clean up argument list by removing elements until the first valid flag\n+      until _flag_list.include?(args[0]) || args.length == 0\n+        # [review] - Make this non-debug print to user?\n+        debug_print \"Unrecognized flag #{ args[0] }\\n\"\n+        args.slice!(0)\n+      end\n+\n+      # Parse command line options\n+      # Grab flag (should be first arg) then slice off args until next flag\n+      # Repeat until all args have been dealt with\n+\n+      until args.length == 0\n+        # Set flag for calling function later\n+        _flag = args.slice!(0)\n+\n+        debug_print \"Current Flag: #{ _flag }\\n\"\n+\n+        # Go through args until we find the next valid flag or all args are parsed\n+        _i = 0\n+        until _flag_list.include?(args[_i]) ||  _i > (args.length - 1)\n+          debug_print \"Arg: #{ args[_i] }\\n\"\n+          _i = _i + 1\n+        end\n+\n+        # Slice off the args for the flag (inclusive) using index from above\n+        # [review] - This is a bit messy (to slice by _i - 1) when we have control\n+        # over the _i index above but I don't want to\n+        # think about the logic right now so look at later\n+        _flag_args = args.slice!(0..(_i-1))\n+\n+        case _flag\n+        when \"-c\", \"--context-depth\"\n+          debug_print \"Found -c/--context-depth argument\\n\"\n+          set_context(_flag_args)\n+\n+        when \"-d\", \"--dirs\"\n+          debug_print \"Found -d/--dirs argument\\n\"\n+          set_dirs(_flag_args)\n+\n+        when \"-f\", \"--files\"\n+          debug_print \"Found -f/--files argument\\n\"\n+          set_files(_flag_args)\n+\n+        when \"-i\", \"--ignore\"\n+          debug_print \"Found -i/--ignore argument\\n\"\n+          set_ignores(_flag_args)\n+\n+        when '--format'\n+          debug_print \"Found --format argument\\n\"\n+          set_output_format(_flag_args)\n+\n+        when \"-p\", \"--parse-depth\"\n+          debug_print \"Found -r/--parse-depth argument\\n\"\n+          set_parse_depth(_flag_args)\n+\n+        when \"-r\", \"--remote\"\n+          debug_print \"Found -r/--remote argument\\n\"\n+          # Run config to populate all the fields and such\n+          # [review] - Not a fan of running these here but want to avoid getting all issues when running remote (which @config.run does)\n+          @config.check_conf\n+          @config.read_conf\n+          setup_remote(_flag_args)\n+\n+          # If setting up remote, exit afterwards\n+          exit true\n+\n+        when \"-s\", \"--show\"\n+          debug_print \"Found -s/--show argument\\n\"\n+          set_show_type(_flag_args)\n+\n+        when \"-t\", \"--tags\"\n+          debug_print \"Found -t/--tags argument\\n\"\n+          set_tags(_flag_args)\n+\n+        when \"-u\", \"--update\"\n+          debug_print \"Found -u/--update argument\\n\"\n+          @config.remote_valid =  true\n+\n+\n+        else\n+          print \"Unknown argument #{ _flag }\\n\"\n+        end\n+      end\n+\n+      debug_print \"Args length 0, running watson...\\n\"\n+      @config.run\n+      structure = @parser.run\n+      @printer.run(structure)\n+\n+      print RESET;\n+    end\n+\n+\n+    ###########################################################\n+    # Print help for watson\n+    def help\n+      # [todo] - Add bold and colored printing\n+\n+      # Identify method entry\n+      debug_print \"#{ self } : #{ __method__ }\\n\"\n+\n+      puts <<-HELP.gsub(/^ {,6}/, '')\n+      #{BOLD}Usage: watson [OPTION]...\n+      Running watson with no arguments will parse with settings in RC file\n+      If no RC file exists, default RC file will be created\n+\n+         -c, --context-depth   lines of context to provide with posted issue\n+         -d, --dirs            list of directories to search in\n+         --debug               enable debug prints from specified class\n+                               all debug prints enabled if no arguments passed\n+         -f, --files           list of files to search in\n+         --format              set output format for watson\n+                               [print, json, unite, silent]\n+         -h, --help            print help\n+         -i, --ignore          list of files, directories, or types to ignore\n+         -p, --parse-depth     depth to recursively parse directories\n+         -r, --remote          list / create tokens for Bitbucket/GitHub\n+         -s, --show            filter results (files listed) based on issue status\n+                               [all, clean, dirty]\n+         -t, --tags            list of tags to search for\n+         -u, --update          update remote repos with current issues\n+         -v, --version         print watson version and info\n+\n+      Any number of files, tags, dirs, and ignores can be listed after flag\n+      Ignored files should be space separated\n+      To use *.filetype identifier, encapsulate in \\\"\\\" to avoid shell substitutions\n+\n+      Report bugs to: watson\\@goosecode.com\n+      watson home page: <http://goosecode.com/watson>\n+      [goosecode] labs | 2012-2013#{RESET}\n+      HELP\n+\n+      return true\n+    end\n+\n+","path":"lib/watson/command.rb","position":222,"original_position":222,"commit_id":"2eb0906071046d4d8fd63cbfc58ecc18de0378f4","original_commit_id":"2eb0906071046d4d8fd63cbfc58ecc18de0378f4","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?","gravatar_id":"38d9cefd9971a05bf447f07c6cd332cc","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Extra blank line detected.","created_at":"2014-04-09T18:54:55Z","updated_at":"2014-04-09T18:54:55Z","html_url":"https://github.com/strudelfish/watson/pull/1#discussion_r11452366","pull_request_url":"https://api.github.com/repos/strudelfish/watson/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/strudelfish/watson/pulls/comments/11452366"},"html":{"href":"https://github.com/strudelfish/watson/pull/1#discussion_r11452366"},"pull_request":{"href":"https://api.github.com/repos/strudelfish/watson/pulls/1"}}}}