Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to Specify PATH in "run" command #331

Merged
merged 5 commits into from
Feb 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/pronto/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def is_thor_reserved_word?(word, type)
end
end

desc 'run', 'Run Pronto'
desc 'run [PATH]', 'Run Pronto'

method_option :'exit-code',
type: :boolean,
Expand Down Expand Up @@ -45,7 +45,9 @@ def is_thor_reserved_word?(word, type)
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}"
Expand All @@ -56,16 +58,19 @@ def run(path = nil)
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
Expand Down