{"action":"created","comment":{"url":"https://api.github.com/repos/exercism/xruby/pulls/comments/94483350","pull_request_review_id":15010882,"id":94483350,"diff_hunk":"@@ -0,0 +1,119 @@\n+require 'logger'\n+require 'optparse'\n+\n+module Generator\n+  # Processes the command line arguments and sets everthing up and returns a\n+  # generator that can be called\n+  class CommandLine\n+    def initialize(paths)\n+      @paths = paths\n+      @options = default_options\n+    end\n+\n+    def parse(args)\n+      parse_options(args)\n+      generator if valid?\n+    end\n+\n+    private\n+\n+    def valid?\n+      validate_paths && validate_options && validate_exercise && validate_cases\n+    end\n+\n+    def generator\n+      generator_class.new(repository)\n+    end\n+\n+    def generator_class\n+      @options[:freeze] ? GenerateTests : UpdateVersionAndGenerateTests\n+    end\n+\n+    def repository\n+      if @options[:verbose]\n+        LoggingRepository.new(paths: @paths, exercise_name: @options[:exercise_name], logger: logger)\n+      else\n+        Repository.new(paths: @paths, exercise_name: @options[:exercise_name])\n+      end\n+    end\n+\n+    def parse_options(args)\n+      args = args.dup\n+      option_parser.parse!(args)\n+      @options[:exercise_name] = args.shift\n+    end\n+\n+    def logger\n+      logger = Logger.new($stdout)\n+      logger.formatter = proc { |_severity, _datetime, _progname, msg| \"#{msg}\\n\" }\n+      logger.level = @options[:verbose] ? Logger::DEBUG : Logger::ERROR\n+      logger\n+    end\n+\n+    def default_options\n+      {\n+        freeze: false,\n+        verbose: false,\n+        exercise_name: nil\n+      }\n+    end\n+\n+    def validate_options\n+      return true unless @options[:help]\n+      $stdout.puts usage\n+      false\n+    end\n+\n+    def validate_paths\n+      validate_metadata_repository\n+    end\n+\n+    def validate_exercise\n+      return true if @options[:exercise_name]\n+      $stderr.puts \"Exercise name required!\\n\"\n+      $stdout.puts usage\n+      false\n+    end\n+\n+    def validate_cases\n+      return true if available_generators.include?(@options[:exercise_name])\n+      $stderr.puts \"A generator does not currently exist for #{@options[:exercise_name]}!\"\n+      false\n+    end\n+\n+    def available_generators\n+      Files::GeneratorCases.available(@paths.track)\n+    end\n+\n+    def option_parser\n+      @option_parser ||= OptionParser.new do |parser|\n+        parser.banner = \"Usage: #{$PROGRAM_NAME} [options] exercise-generator\"\n+        parser.on('-f', '--freeze', 'Don\\'t update test version') { |value| @options[:freeze] = value }\n+        parser.on('-h', '--help', 'Displays this help message') { |value| @options[:help] = value }\n+        parser.on('-v', '--verbose', 'Display progress messages') { |value| @options[:verbose] = value }\n+      end\n+    end\n+\n+    def usage\n+      option_parser.help +","path":"lib/generator/command_line.rb","position":98,"original_position":98,"commit_id":"68ec1a4ee9ded8b327ec8f2ac300b694e206a28c","original_commit_id":"68ec1a4ee9ded8b327ec8f2ac300b694e206a28c","user":{"login":"kotp","id":16747,"avatar_url":"https://avatars.githubusercontent.com/u/16747?v=3","gravatar_id":"","url":"https://api.github.com/users/kotp","html_url":"https://github.com/kotp","followers_url":"https://api.github.com/users/kotp/followers","following_url":"https://api.github.com/users/kotp/following{/other_user}","gists_url":"https://api.github.com/users/kotp/gists{/gist_id}","starred_url":"https://api.github.com/users/kotp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kotp/subscriptions","organizations_url":"https://api.github.com/users/kotp/orgs","repos_url":"https://api.github.com/users/kotp/repos","events_url":"https://api.github.com/users/kotp/events{/privacy}","received_events_url":"https://api.github.com/users/kotp/received_events","type":"User","site_admin":false},"body":"Prefer using `<<` to concatenate the strings, as it uses a single string, appropriately.  One string for the garbage collector.","created_at":"2017-01-03T21:03:19Z","updated_at":"2017-01-03T21:19:54Z","html_url":"https://github.com/exercism/xruby/pull/522#discussion_r94483350","pull_request_url":"https://api.github.com/repos/exercism/xruby/pulls/522","_links":{"self":{"href":"https://api.github.com/repos/exercism/xruby/pulls/comments/94483350"},"html":{"href":"https://github.com/exercism/xruby/pull/522#discussion_r94483350"},"pull_request":{"href":"https://api.github.com/repos/exercism/xruby/pulls/522"}}},"pull_request":{"url":"https://api.github.com/repos/exercism/xruby/pulls/522","id":99632506,"html_url":"https://github.com/exercism/xruby/pull/522","diff_url":"https://github.com/exercism/xruby/pull/522.diff","patch_url":"https://github.com/exercism/xruby/pull/522.patch","issue_url":"https://api.github.com/repos/exercism/xruby/issues/522","number":522,"state":"open","locked":false,"title":"bin/generator: Big rewrite","user":{"login":"Insti","id":5096681,"avatar_url":"https://avatars.githubusercontent.com/u/5096681?v=3","gravatar_id":"","url":"https://api.github.com/users/Insti","html_url":"https://github.com/Insti","followers_url":"https://api.github.com/users/Insti/followers","following_url":"https://api.github.com/users/Insti/following{/other_user}","gists_url":"https://api.github.com/users/Insti/gists{/gist_id}","starred_url":"https://api.github.com/users/Insti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Insti/subscriptions","organizations_url":"https://api.github.com/users/Insti/orgs","repos_url":"https://api.github.com/users/Insti/repos","events_url":"https://api.github.com/users/Insti/events{/privacy}","received_events_url":"https://api.github.com/users/Insti/received_events","type":"User","site_admin":false},"body":"Can now generate tests without updating the test version number.\r\n\r\nNew command line options:\r\n```\r\nUsage: bin/generate [options] exercise-generator\r\n\t-f, --freeze                     Don't update test version\r\n\t-h, --help                       Displays this help message\r\n\t-v, --verbose                    Display progress messages\r\n```\r\n\r\n`sha1` in the \"Common test data version: <%= sha1 %>\" comment is now the\r\ncommit ID of the relevant canonical-data.json file\r\n\r\nFiles will only be written if they have changed.\r\n\r\nSplit code up into classes.\r\n100% test coverage.\r\n\r\nAdded dependency: `require_all` gem\r\n    \r\nJust requiring files in (potentially random) directory order was not sufficient to satisfy all class dependencies. The `require_all` gem ensures dependencies are met as the files are `require`d\r\n","created_at":"2016-12-29T09:03:00Z","updated_at":"2017-01-03T21:19:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"71b1b9ab2fb60785e1d397ce65b32185c761f91a","assignee":{"login":"kotp","id":16747,"avatar_url":"https://avatars.githubusercontent.com/u/16747?v=3","gravatar_id":"","url":"https://api.github.com/users/kotp","html_url":"https://github.com/kotp","followers_url":"https://api.github.com/users/kotp/followers","following_url":"https://api.github.com/users/kotp/following{/other_user}","gists_url":"https://api.github.com/users/kotp/gists{/gist_id}","starred_url":"https://api.github.com/users/kotp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kotp/subscriptions","organizations_url":"https://api.github.com/users/kotp/orgs","repos_url":"https://api.github.com/users/kotp/repos","events_url":"https://api.github.com/users/kotp/events{/privacy}","received_events_url":"https://api.github.com/users/kotp/received_events","type":"User","site_admin":false},"assignees":[{"login":"kotp","id":16747,"avatar_url":"https://avatars.githubusercontent.com/u/16747?v=3","gravatar_id":"","url":"https://api.github.com/users/kotp","html_url":"https://github.com/kotp","followers_url":"https://api.github.com/users/kotp/followers","following_url":"https://api.github.com/users/kotp/following{/other_user}","gists_url":"https://api.github.com/users/kotp/gists{/gist_id}","starred_url":"https://api.github.com/users/kotp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kotp/subscriptions","organizations_url":"https://api.github.com/users/kotp/orgs","repos_url":"https://api.github.com/users/kotp/repos","events_url":"https://api.github.com/users/kotp/events{/privacy}","received_events_url":"https://api.github.com/users/kotp/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/exercism/xruby/pulls/522/commits","review_comments_url":"https://api.github.com/repos/exercism/xruby/pulls/522/comments","review_comment_url":"https://api.github.com/repos/exercism/xruby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/exercism/xruby/issues/522/comments","statuses_url":"https://api.github.com/repos/exercism/xruby/statuses/68ec1a4ee9ded8b327ec8f2ac300b694e206a28c","head":{"label":"Insti:Generator_2.0","ref":"Generator_2.0","sha":"68ec1a4ee9ded8b327ec8f2ac300b694e206a28c","user":{"login":"Insti","id":5096681,"avatar_url":"https://avatars.githubusercontent.com/u/5096681?v=3","gravatar_id":"","url":"https://api.github.com/users/Insti","html_url":"https://github.com/Insti","followers_url":"https://api.github.com/users/Insti/followers","following_url":"https://api.github.com/users/Insti/following{/other_user}","gists_url":"https://api.github.com/users/Insti/gists{/gist_id}","starred_url":"https://api.github.com/users/Insti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Insti/subscriptions","organizations_url":"https://api.github.com/users/Insti/orgs","repos_url":"https://api.github.com/users/Insti/repos","events_url":"https://api.github.com/users/Insti/events{/privacy}","received_events_url":"https://api.github.com/users/Insti/received_events","type":"User","site_admin":false},"repo":{"id":58808555,"name":"xruby","full_name":"Insti/xruby","owner":{"login":"Insti","id":5096681,"avatar_url":"https://avatars.githubusercontent.com/u/5096681?v=3","gravatar_id":"","url":"https://api.github.com/users/Insti","html_url":"https://github.com/Insti","followers_url":"https://api.github.com/users/Insti/followers","following_url":"https://api.github.com/users/Insti/following{/other_user}","gists_url":"https://api.github.com/users/Insti/gists{/gist_id}","starred_url":"https://api.github.com/users/Insti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Insti/subscriptions","organizations_url":"https://api.github.com/users/Insti/orgs","repos_url":"https://api.github.com/users/Insti/repos","events_url":"https://api.github.com/users/Insti/events{/privacy}","received_events_url":"https://api.github.com/users/Insti/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Insti/xruby","description":"Exercism Exercises in Ruby","fork":true,"url":"https://api.github.com/repos/Insti/xruby","forks_url":"https://api.github.com/repos/Insti/xruby/forks","keys_url":"https://api.github.com/repos/Insti/xruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Insti/xruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Insti/xruby/teams","hooks_url":"https://api.github.com/repos/Insti/xruby/hooks","issue_events_url":"https://api.github.com/repos/Insti/xruby/issues/events{/number}","events_url":"https://api.github.com/repos/Insti/xruby/events","assignees_url":"https://api.github.com/repos/Insti/xruby/assignees{/user}","branches_url":"https://api.github.com/repos/Insti/xruby/branches{/branch}","tags_url":"https://api.github.com/repos/Insti/xruby/tags","blobs_url":"https://api.github.com/repos/Insti/xruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Insti/xruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Insti/xruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/Insti/xruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Insti/xruby/statuses/{sha}","languages_url":"https://api.github.com/repos/Insti/xruby/languages","stargazers_url":"https://api.github.com/repos/Insti/xruby/stargazers","contributors_url":"https://api.github.com/repos/Insti/xruby/contributors","subscribers_url":"https://api.github.com/repos/Insti/xruby/subscribers","subscription_url":"https://api.github.com/repos/Insti/xruby/subscription","commits_url":"https://api.github.com/repos/Insti/xruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/Insti/xruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/Insti/xruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/Insti/xruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/Insti/xruby/contents/{+path}","compare_url":"https://api.github.com/repos/Insti/xruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Insti/xruby/merges","archive_url":"https://api.github.com/repos/Insti/xruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Insti/xruby/downloads","issues_url":"https://api.github.com/repos/Insti/xruby/issues{/number}","pulls_url":"https://api.github.com/repos/Insti/xruby/pulls{/number}","milestones_url":"https://api.github.com/repos/Insti/xruby/milestones{/number}","notifications_url":"https://api.github.com/repos/Insti/xruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Insti/xruby/labels{/name}","releases_url":"https://api.github.com/repos/Insti/xruby/releases{/id}","deployments_url":"https://api.github.com/repos/Insti/xruby/deployments","created_at":"2016-05-14T13:13:19Z","updated_at":"2016-05-14T13:13:20Z","pushed_at":"2017-01-02T20:00:41Z","git_url":"git://github.com/Insti/xruby.git","ssh_url":"git@github.com:Insti/xruby.git","clone_url":"https://github.com/Insti/xruby.git","svn_url":"https://github.com/Insti/xruby","homepage":null,"size":973,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"exercism:master","ref":"master","sha":"d88dc7a94fd364952313f8ee98d08f98ae8850a4","user":{"login":"exercism","id":5624255,"avatar_url":"https://avatars.githubusercontent.com/u/5624255?v=3","gravatar_id":"","url":"https://api.github.com/users/exercism","html_url":"https://github.com/exercism","followers_url":"https://api.github.com/users/exercism/followers","following_url":"https://api.github.com/users/exercism/following{/other_user}","gists_url":"https://api.github.com/users/exercism/gists{/gist_id}","starred_url":"https://api.github.com/users/exercism/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exercism/subscriptions","organizations_url":"https://api.github.com/users/exercism/orgs","repos_url":"https://api.github.com/users/exercism/repos","events_url":"https://api.github.com/users/exercism/events{/privacy}","received_events_url":"https://api.github.com/users/exercism/received_events","type":"Organization","site_admin":false},"repo":{"id":17258847,"name":"xruby","full_name":"exercism/xruby","owner":{"login":"exercism","id":5624255,"avatar_url":"https://avatars.githubusercontent.com/u/5624255?v=3","gravatar_id":"","url":"https://api.github.com/users/exercism","html_url":"https://github.com/exercism","followers_url":"https://api.github.com/users/exercism/followers","following_url":"https://api.github.com/users/exercism/following{/other_user}","gists_url":"https://api.github.com/users/exercism/gists{/gist_id}","starred_url":"https://api.github.com/users/exercism/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exercism/subscriptions","organizations_url":"https://api.github.com/users/exercism/orgs","repos_url":"https://api.github.com/users/exercism/repos","events_url":"https://api.github.com/users/exercism/events{/privacy}","received_events_url":"https://api.github.com/users/exercism/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/exercism/xruby","description":"Exercism Exercises in Ruby","fork":false,"url":"https://api.github.com/repos/exercism/xruby","forks_url":"https://api.github.com/repos/exercism/xruby/forks","keys_url":"https://api.github.com/repos/exercism/xruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/exercism/xruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/exercism/xruby/teams","hooks_url":"https://api.github.com/repos/exercism/xruby/hooks","issue_events_url":"https://api.github.com/repos/exercism/xruby/issues/events{/number}","events_url":"https://api.github.com/repos/exercism/xruby/events","assignees_url":"https://api.github.com/repos/exercism/xruby/assignees{/user}","branches_url":"https://api.github.com/repos/exercism/xruby/branches{/branch}","tags_url":"https://api.github.com/repos/exercism/xruby/tags","blobs_url":"https://api.github.com/repos/exercism/xruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/exercism/xruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/exercism/xruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/exercism/xruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/exercism/xruby/statuses/{sha}","languages_url":"https://api.github.com/repos/exercism/xruby/languages","stargazers_url":"https://api.github.com/repos/exercism/xruby/stargazers","contributors_url":"https://api.github.com/repos/exercism/xruby/contributors","subscribers_url":"https://api.github.com/repos/exercism/xruby/subscribers","subscription_url":"https://api.github.com/repos/exercism/xruby/subscription","commits_url":"https://api.github.com/repos/exercism/xruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/exercism/xruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/exercism/xruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/exercism/xruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/exercism/xruby/contents/{+path}","compare_url":"https://api.github.com/repos/exercism/xruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/exercism/xruby/merges","archive_url":"https://api.github.com/repos/exercism/xruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/exercism/xruby/downloads","issues_url":"https://api.github.com/repos/exercism/xruby/issues{/number}","pulls_url":"https://api.github.com/repos/exercism/xruby/pulls{/number}","milestones_url":"https://api.github.com/repos/exercism/xruby/milestones{/number}","notifications_url":"https://api.github.com/repos/exercism/xruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/exercism/xruby/labels{/name}","releases_url":"https://api.github.com/repos/exercism/xruby/releases{/id}","deployments_url":"https://api.github.com/repos/exercism/xruby/deployments","created_at":"2014-02-27T18:11:43Z","updated_at":"2016-12-31T01:04:27Z","pushed_at":"2017-01-03T03:37:50Z","git_url":"git://github.com/exercism/xruby.git","ssh_url":"git@github.com:exercism/xruby.git","clone_url":"https://github.com/exercism/xruby.git","svn_url":"https://github.com/exercism/xruby","homepage":null,"size":942,"stargazers_count":152,"watchers_count":152,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":219,"mirror_url":null,"open_issues_count":25,"forks":219,"open_issues":25,"watchers":152,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/exercism/xruby/pulls/522"},"html":{"href":"https://github.com/exercism/xruby/pull/522"},"issue":{"href":"https://api.github.com/repos/exercism/xruby/issues/522"},"comments":{"href":"https://api.github.com/repos/exercism/xruby/issues/522/comments"},"review_comments":{"href":"https://api.github.com/repos/exercism/xruby/pulls/522/comments"},"review_comment":{"href":"https://api.github.com/repos/exercism/xruby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/exercism/xruby/pulls/522/commits"},"statuses":{"href":"https://api.github.com/repos/exercism/xruby/statuses/68ec1a4ee9ded8b327ec8f2ac300b694e206a28c"}}}}
{"actor":{"display_login":"kotp"}}