Class: Diogenes::Cli

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

Defined Under Namespace

Classes: Build, Evaluate, Init, Validate, Watch

Constant Summary collapse

COMMANDS =
{
  "init" => Init,
  "build" => Build,
  "evaluate" => Evaluate,
  "validate" => Validate,
  "watch" => Watch
}.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



26
27
28
29
30
31
32
# File 'lib/diogenes/cli.rb', line 26

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

Class Method Details

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

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



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

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/diogenes/cli.rb', line 35

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