lib/pronto/cli.rb in pronto-0.8.2 vs lib/pronto/cli.rb in pronto-0.9.0

- old
+ new

@@ -22,15 +22,19 @@ type: :string, default: 'master', aliases: '-c', desc: 'Commit for the diff' - method_option :index, + method_option :unstaged, type: :boolean, - aliases: '-i', - desc: 'Analyze changes in git index (staging area)' + aliases: ['-i', '--index'], + desc: 'Analyze changes made, but not in git staging area' + method_option :staged, + type: :boolean, + desc: 'Analyze changes in git staging area' + method_option :runner, type: :array, default: [], aliases: '-r', desc: 'Run only the passed runners' @@ -46,37 +50,42 @@ gem_names.each do |gem_name| require "pronto/#{gem_name}" end formatters = ::Pronto::Formatter.get(options[:formatters]) - commit = options[:index] ? :index : options[:commit] + + commit_options = %i[staged unstaged index] + commit = commit_options.find { |o| options[o] } || options[:commit] + repo_workdir = ::Rugged::Repository.discover('.').workdir messages = Dir.chdir(repo_workdir) do ::Pronto.run(commit, '.', formatters, path) end if options[:'exit-code'] error_messages_count = messages.count { |m| m.level != :info } exit(error_messages_count) end rescue Rugged::RepositoryError puts '"pronto" should be run from a git repository' + rescue Pronto::Error => e + $stderr.puts "Pronto errored: #{e.message}" end desc 'list', 'Lists pronto runners that are available to be used' def list puts ::Pronto::GemNames.new.to_a end desc 'version', 'Display version' - map %w(-v --version) => :version + map %w[-v --version] => :version def version puts Version::STRING end desc 'verbose-version', 'Display verbose version' - map %w(-V --verbose-version) => :verbose_version + map %w[-V --verbose-version] => :verbose_version def verbose_version puts Version.verbose end end