Class: MRubyPortable::CLI
- Inherits:
-
Object
- Object
- MRubyPortable::CLI
- Defined in:
- lib/mruby_portable/cli.rb
Instance Attribute Summary collapse
-
#err ⇒ Object
readonly
Returns the value of attribute err.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(out:, err:, runner:) ⇒ CLI
constructor
A new instance of CLI.
- #run(argv) ⇒ Object
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
#err ⇒ Object (readonly)
Returns the value of attribute err.
7 8 9 |
# File 'lib/mruby_portable/cli.rb', line 7 def err @err end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
7 8 9 |
# File 'lib/mruby_portable/cli.rb', line 7 def out @out end |
#runner ⇒ Object (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.}" 1 end |