Class: Molder::CLI
- Inherits:
-
Object
- Object
- Molder::CLI
- Defined in:
- lib/molder/cli.rb
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Instance Attribute Summary collapse
-
#argv ⇒ Object
Returns the value of attribute argv.
-
#command ⇒ Object
Returns the value of attribute command.
-
#config ⇒ Object
Returns the value of attribute config.
-
#kernel ⇒ Object
readonly
Returns the value of attribute kernel.
-
#options ⇒ Object
Returns the value of attribute options.
-
#original_argv ⇒ Object
Returns the value of attribute original_argv.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ CLI
constructor
A new instance of CLI.
Constructor Details
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ CLI
Returns a new instance of CLI.
16 17 18 19 20 21 22 23 24 |
# File 'lib/molder/cli.rb', line 16 def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel self. = Hashie::Mash.new self.[:max_processes] = Etc.nprocessors - 2 self.argv = argv.dup self.original_argv = argv.dup self.class.instance = self end |
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
13 14 15 |
# File 'lib/molder/cli.rb', line 13 def instance @instance end |
Instance Attribute Details
#argv ⇒ Object
Returns the value of attribute argv.
9 10 11 |
# File 'lib/molder/cli.rb', line 9 def argv @argv end |
#command ⇒ Object
Returns the value of attribute command.
9 10 11 |
# File 'lib/molder/cli.rb', line 9 def command @command end |
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/molder/cli.rb', line 9 def config @config end |
#kernel ⇒ Object (readonly)
Returns the value of attribute kernel.
10 11 12 |
# File 'lib/molder/cli.rb', line 10 def kernel @kernel end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/molder/cli.rb', line 9 def @options end |
#original_argv ⇒ Object
Returns the value of attribute original_argv.
9 10 11 |
# File 'lib/molder/cli.rb', line 9 def original_argv @original_argv end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
10 11 12 |
# File 'lib/molder/cli.rb', line 10 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
10 11 12 |
# File 'lib/molder/cli.rb', line 10 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
10 11 12 |
# File 'lib/molder/cli.rb', line 10 def stdout @stdout end |
Instance Method Details
#execute! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/molder/cli.rb', line 26 def execute! self.argv << '-h' if argv.empty? parser.parse!(self.argv) if .help @kernel.exit(0) return end exit_code = begin $stderr = @stderr $stdin = @stdin $stdout = @stdout parse_args! App.new(config: config, options: , command_name: command).execute! 0 rescue StandardError => e report_error(exception: e) 1 rescue SystemExit => e e.status ensure $stderr = STDERR $stdin = STDIN $stdout = STDOUT end @kernel.exit(exit_code) end |