Module: Boson::BinRunner::API
- Included in:
- Boson::BinRunner
- Defined in:
- lib/boson/bin_runner.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
Instance Method Summary collapse
-
#command_name(cmd) ⇒ Object
Determine command name given full command name.
-
#command_not_found?(cmd) ⇒ Boolean
Determines if a NoMethodError is a command not found error.
-
#default_error_message(err) ⇒ Object
Constructs error message.
-
#early_option?(args) ⇒ Boolean
Returns true if an option does something and exits early.
-
#eval_execute_option(str) ⇒ Object
Evaluates :execute option.
-
#execute_option_or_command(options, command, args) ⇒ Object
Executes functionality from either an option or a command.
-
#no_method_error_message(err) ⇒ Object
Handles no method errors.
-
#print_usage ⇒ Object
prints full usage.
- #print_usage_header ⇒ Object
-
#verbose ⇒ Object
Determines verbosity of this class.
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
20 21 22 |
# File 'lib/boson/bin_runner.rb', line 20 def command @command end |
Instance Method Details
#command_name(cmd) ⇒ Object
Determine command name given full command name. Overridden by namespaces
64 65 66 |
# File 'lib/boson/bin_runner.rb', line 64 def command_name(cmd) cmd end |
#command_not_found?(cmd) ⇒ Boolean
Determines if a NoMethodError is a command not found error
69 70 71 |
# File 'lib/boson/bin_runner.rb', line 69 def command_not_found?(cmd) cmd[/\w+/] end |
#default_error_message(err) ⇒ Object
Constructs error message
74 75 76 |
# File 'lib/boson/bin_runner.rb', line 74 def (err) "Error: #{err.}" end |
#early_option?(args) ⇒ Boolean
Returns true if an option does something and exits early
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/boson/bin_runner.rb', line 34 def early_option?(args) if @options[:version] puts("boson #{Boson::VERSION}") true elsif args.empty? || (@command.nil? && !@options[:execute]) print_usage true else false end end |
#eval_execute_option(str) ⇒ Object
Evaluates :execute option.
29 30 31 |
# File 'lib/boson/bin_runner.rb', line 29 def eval_execute_option(str) Boson.main_object.instance_eval str end |
#execute_option_or_command(options, command, args) ⇒ Object
Executes functionality from either an option or a command
23 24 25 26 |
# File 'lib/boson/bin_runner.rb', line 23 def execute_option_or_command(, command, args) [:execute] ? eval_execute_option([:execute]) : execute_command(command, args) end |
#no_method_error_message(err) ⇒ Object
Handles no method errors
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/boson/bin_runner.rb', line 52 def (err) @command = @command.to_s if err.backtrace.grep(/`(invoke|full_invoke)'$/).empty? || !err.[/undefined method `(\w+\.)?#{command_name(@command)}'/] ($!) else command_not_found?(@command) ? "Error: Command '#{@command}' not found" : (err) end end |
#print_usage ⇒ Object
prints full usage
83 84 85 86 |
# File 'lib/boson/bin_runner.rb', line 83 def print_usage print_usage_header @option_parser.print_usage_table end |
#print_usage_header ⇒ Object
78 79 80 |
# File 'lib/boson/bin_runner.rb', line 78 def print_usage_header puts "boson [GLOBAL OPTIONS] [COMMAND] [ARGS] [COMMAND OPTIONS]\n\n" end |
#verbose ⇒ Object
Determines verbosity of this class
47 48 49 |
# File 'lib/boson/bin_runner.rb', line 47 def verbose false end |