Class: MRubyPortable::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/mruby_portable/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out:, err:, runner:) ⇒ CLI

Returns a new instance of CLI.



13
14
15
16
17
# File 'lib/mruby_portable/cli.rb', line 13

def initialize(out:, err:, runner:)
  @out = out
  @err = err
  @runner = runner
end

Instance Attribute Details

#errObject (readonly)

Returns the value of attribute err.



7
8
9
# File 'lib/mruby_portable/cli.rb', line 7

def err
  @err
end

#outObject (readonly)

Returns the value of attribute out.



7
8
9
# File 'lib/mruby_portable/cli.rb', line 7

def out
  @out
end

#runnerObject (readonly)

Returns the value of attribute runner.



7
8
9
# File 'lib/mruby_portable/cli.rb', line 7

def runner
  @runner
end

Class Method Details

.start(argv = ARGV, out: $stdout, err: $stderr, runner: Runner.new) ⇒ Object



9
10
11
# File 'lib/mruby_portable/cli.rb', line 9

def self.start(argv = ARGV, out: $stdout, err: $stderr, runner: Runner.new)
  new(out: out, err: err, runner: runner).run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mruby_portable/cli.rb', line 19

def run(argv)
  command = argv.shift

  case command
  when nil, "-h", "--help"
    out.puts help
    0
  when "-v", "--version"
    out.puts VERSION
    0
  when "new"
    run_new(argv)
  when "build"
    run_build(argv)
  when "doctor"
    run_doctor(argv)
  when "image"
    run_image(argv)
  else
    raise Error, "unknown command: #{command}"
  end
rescue Error, OptionParser::ParseError => e
  err.puts "mrp: #{e.message}"
  1
end