Class: Boson::BareRunner
- Inherits:
-
Object
- Object
- Boson::BareRunner
- Extended by:
- API
- Defined in:
- lib/boson/bare_runner.rb
Overview
Base class for runners.
Defined Under Namespace
Modules: API
Constant Summary collapse
- DEFAULT_LIBRARIES =
[]
- GLOBAL_OPTIONS =
Default options for parse_args
{ help: { type: :boolean, desc: "Displays this help message" } }
Class Method Summary collapse
-
.allowed_argument_error?(err, cmd, args) ⇒ Boolean
Determines if a user command argument error or an internal Boson one.
-
.execute_command(cmd, args) ⇒ Object
Executes a command and handles invalid args.
-
.no_command_error(cmd) ⇒ Object
Use to abort when no command found.
- .option_parser ⇒ Object
Methods included from API
abort_with, all_libraries, default_libraries, init, start
Class Method Details
.allowed_argument_error?(err, cmd, args) ⇒ Boolean
Determines if a user command argument error or an internal Boson one
58 59 60 61 62 63 |
# File 'lib/boson/bare_runner.rb', line 58 def allowed_argument_error?(err, cmd, args) msg = RUBY_ENGINE == 'rbx' && err.class == ArgumentError ? /given \d+, expected \d+/ : /wrong number of arguments/ err.[msg] && (cmd_obj = Command.find(cmd)) && cmd_obj.incorrect_arg_size?(args) end |
.execute_command(cmd, args) ⇒ Object
Executes a command and handles invalid args
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/boson/bare_runner.rb', line 41 def execute_command(cmd, args) Boson.full_invoke(cmd, args) rescue ArgumentError raise if !allowed_argument_error?($!, cmd, args) abort_with "'#{cmd}' was called incorrectly.\nUsage: " + Command.usage(cmd) rescue NoMethodError => err index = RUBY_ENGINE == 'rbx' ? 1 : 0 raise if !err.backtrace[index].include?('`full_invoke') no_command_error cmd end |
.no_command_error(cmd) ⇒ Object
Use to abort when no command found
53 54 55 |
# File 'lib/boson/bare_runner.rb', line 53 def no_command_error(cmd) abort_with %[Could not find command "#{cmd}"] end |
.option_parser ⇒ Object
65 66 67 |
# File 'lib/boson/bare_runner.rb', line 65 def option_parser @option_parser ||= OptionParser.new(self::GLOBAL_OPTIONS) end |