lib/pronto/cli.rb in pronto-0.9.5 vs lib/pronto/cli.rb in pronto-0.10.0

- old
+ new

@@ -10,11 +10,11 @@ return false if word == 'run' super end end - desc 'run', 'Run Pronto' + desc 'run [PATH]', 'Run Pronto' method_option :'exit-code', type: :boolean, desc: 'Exits with non-zero code if there were any warnings/errors.' @@ -43,30 +43,35 @@ type: :array, default: ['text'], aliases: ['formatter', '-f'], desc: "Pick output formatters. Available: #{::Pronto::Formatter.names.join(', ')}" - def run(path = nil) + def run(path = '.') + path = File.expand_path(path) + gem_names = options[:runner].any? ? options[:runner] : ::Pronto::GemNames.new.to_a gem_names.each do |gem_name| require "pronto/#{gem_name}" end formatters = ::Pronto::Formatter.get(options[:formatters]) commit_options = %i[staged unstaged index] commit = commit_options.find { |o| options[o] } || options[:commit] - repo_workdir = ::Rugged::Repository.discover('.').workdir + repo_workdir = ::Rugged::Repository.discover(path).workdir + relative = path.sub(repo_workdir, '') + messages = Dir.chdir(repo_workdir) do - ::Pronto.run(commit, '.', formatters, path) + file = relative.length != path.length ? relative : nil + ::Pronto.run(commit, '.', formatters, file) 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' + puts '"pronto" must be run from within a git repository or must be supplied the path to 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'