Class: Recheck::Cli
- Inherits:
-
Object
- Object
- Recheck::Cli
- Defined in:
- lib/recheck/cli.rb
Constant Summary collapse
- EXIT_CODE =
{ no_errors: 0, # all checks passed any_errors: 1, # any check returns fail or threw an exception load_error: 2, # error loading checker/reporter recheck_error: 3 # recheck itself encountered an error }.freeze
- COMMANDS =
{ reporters: "List available reporters", run: "Run checks", setup: "Set up a new check suite in the current directory" }.freeze
Instance Method Summary collapse
-
#initialize(argv: []) ⇒ Cli
constructor
A new instance of Cli.
- #run ⇒ Object
Constructor Details
#initialize(argv: []) ⇒ Cli
Returns a new instance of Cli.
16 17 18 |
# File 'lib/recheck/cli.rb', line 16 def initialize(argv: []) @argv = argv end |
Instance Method Details
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/recheck/cli.rb', line 20 def run = Recheck::Optimist.(@argv) do version "recheck v#{Recheck::VERSION}" "Usage:" " recheck [global options] [<command> [options]]" "\nGlobal options:" opt :version, "Print version and exit", short: :v opt :help, "Print help", short: :h stop_on COMMANDS.keys.map(&:to_s) "\nCommands:" COMMANDS.each { |c, desc| format(" %-10s %s", c, desc) } end command = [:_leftovers].shift&.to_sym || :help Recheck::Optimist.die "unknown command '#{command}'" unless COMMANDS.include? command Recheck::Command.const_get(command.to_s.split("_").map(&:capitalize).join("")).new(argv: [:_leftovers]).run exit EXIT_CODE[:no_errors] rescue Interrupt puts "\nOperation cancelled by user." exit EXIT_CODE[:recheck_error] end |