Class: Evilution::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/cli.rb,
lib/evilution/cli/result.rb,
lib/evilution/cli/parsed_args.rb

Defined Under Namespace

Modules: Commands, Dispatcher, Printers Classes: Command, ParsedArgs, Parser, Result

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin: $stdin) ⇒ CLI

Returns a new instance of CLI.



22
23
24
25
26
27
28
29
30
31
# File 'lib/evilution/cli.rb', line 22

def initialize(argv, stdin: $stdin)
  parsed = Parser.new(argv, stdin: stdin).parse
  @parsed = parsed
  @command = parsed.command
  @options = parsed.options
  @files = parsed.files
  @line_ranges = parsed.line_ranges
  @stdin_error = parsed.stdin_error
  @parse_error = parsed.parse_error
end

Instance Method Details

#callObject



33
34
35
36
37
38
39
# File 'lib/evilution/cli.rb', line 33

def call
  return run_subcommand_error(@parse_error) if @command == :parse_error

  result = Dispatcher.lookup(@command).new(@parsed, stdout: $stdout, stderr: $stderr).call
  warn("Error: #{result.error.message}") if result.error && !result.error_rendered
  result.exit_code
end