Class: Boson::Runner
Overview
Defines a RunnerLibrary for use by executables as a simple way to map methods to subcommands
Defined Under Namespace
Modules: CommandExtension, ScientistExtension
Constant Summary
Constants inherited
from BareRunner
BareRunner::DEFAULT_LIBRARIES, BareRunner::GLOBAL_OPTIONS
Class Attribute Summary collapse
Class Method Summary
collapse
Methods inherited from BareRunner
allowed_argument_error?, no_command_error, option_parser
#abort_with, #all_libraries, #default_libraries, #init, #start
Class Attribute Details
.current ⇒ Object
Returns the value of attribute current.
8
9
10
|
# File 'lib/boson/runner.rb', line 8
def current
@current
end
|
Class Method Details
.abort_with(msg) ⇒ Object
61
62
63
|
# File 'lib/boson/runner.rb', line 61
def self.abort_with(msg)
super "#{app_name}: #{msg}"
end
|
.app_name ⇒ Object
57
58
59
|
# File 'lib/boson/runner.rb', line 57
def self.app_name
File.basename($0).split(' ').first
end
|
.default_libraries ⇒ Object
15
16
17
|
# File 'lib/boson/runner.rb', line 15
def self.default_libraries
[self, DefaultCommandsRunner]
end
|
.display_command_help(cmd) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/boson/runner.rb', line 40
def self.display_command_help(cmd)
puts "Usage: #{app_name} #{cmd.name} #{cmd.basic_usage}".rstrip, ""
if cmd.options
puts "Options:"
cmd.option_parser.print_usage_table(no_headers: true)
puts ""
end
puts "Description:\n #{cmd.desc || 'TODO'}"
end
|
.display_help ⇒ Object
50
51
52
53
54
55
|
# File 'lib/boson/runner.rb', line 50
def self.display_help
commands = Boson.commands.sort_by(&:name).map {|c| [c.name, c.desc.to_s] }
puts "Usage: #{app_name} [OPTIONS] COMMAND [ARGS]", "", "Available commands:",
Util.format_table(commands), "", "Options:"
option_parser.print_usage_table(no_headers: true)
end
|
.execute(command, args, options) ⇒ Object
29
30
31
32
|
# File 'lib/boson/runner.rb', line 29
def self.execute(command, args, options)
options[:help] || command.nil? ? display_help :
execute_command(command, args, options)
end
|
.execute_command(cmd, args, options) ⇒ Object
34
35
36
37
38
|
# File 'lib/boson/runner.rb', line 34
def self.execute_command(cmd, args, options)
Command.find(cmd) ? super(cmd, args) : no_command_error(cmd)
rescue OptionParser::Error => err
abort_with err.message
end
|
.inherited(mod) ⇒ Object
10
11
12
13
|
# File 'lib/boson/runner.rb', line 10
def self.inherited(mod)
@help_added ||= add_command_help
Inspector.enable all_classes: true, module: mod.singleton_class
end
|
.start(args = ARGV) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/boson/runner.rb', line 19
def self.start(args=ARGV)
Runner.current = self
Boson.in_shell = true
ENV['BOSONRC'] ||= ''
super
init
command, options, args = parse_args(args)
execute command, args, options
end
|