Class: Diogenes::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/diogenes/cli.rb,
lib/diogenes/cli/init.rb,
lib/diogenes/cli/evaluate.rb

Defined Under Namespace

Classes: Evaluate, Init

Constant Summary collapse

COMMANDS =
{
  "init" => Init,
  "evaluate" => Evaluate
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv:, out:, err:, **opts) ⇒ Cli

: (argv: Array, out: IO, err: IO, **untyped) -> void



20
21
22
23
24
25
# File 'lib/diogenes/cli.rb', line 20

def initialize(argv:, out:, err:, **opts)
  @argv = argv.dup #: Array[String]
  @out = out #: IO
  @err = err #: IO
  @in = opts.fetch(:in, $stdin) #: IO
end

Class Method Details

.run(argv = ARGV, out: $stdout, err: $stderr, **opts) ⇒ Object

: (?Array argv, ?out: IO, ?err: IO, **untyped) -> Integer



15
16
17
# File 'lib/diogenes/cli.rb', line 15

def self.run(argv = ARGV, out: $stdout, err: $stderr, **opts)
  new(argv: argv, out: out, err: err, **opts).run
end

Instance Method Details

#runObject

: () -> Integer



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/diogenes/cli.rb', line 28

def run
  command, *args = @argv

  case command
  when nil, "help", "-h", "--help"
    print_help
  when "version", "-v", "--version"
    print_version
  when *COMMANDS.keys
    run_command(COMMANDS.fetch(command), args)
  else
    raise UserError, unknown_command_message(command)
  end
rescue OptionParser::ParseError, UserError => e
  @err.puts e.message
  1
end