diff --git a/bin/cli.rb b/bin/cli.rb index b8335615..ec224b69 100644 --- a/bin/cli.rb +++ b/bin/cli.rb @@ -84,29 +84,31 @@ def self.extended(base) # Redefine the Thor CLI entrypoint and exception handling def start(args, config={}) - # Copy args as Thor changes them within the call chain of dispatch() - _args = args.clone() - - # Call Thor's handlers as it does in start() - config[:shell] ||= Thor::Base.shell.new - dispatch(nil, args, nil, config) - - # Handle undefined commands at top-level and for `help ` - rescue Thor::UndefinedCommandError => ex - # Handle `help` for an argument that is not an application command such as `new` or `build` - if _args[0].downcase() == 'help' - - # Raise fatal StandardError to differentiate from UndefinedCommandError - msg = "Argument '#{_args[1]}' is not a recognized application command with detailed help. " + - "It may be a build / plugin task without detailed help or simply a goof." - raise( msg ) - - # Otherwise, eat unhandled command errors - else - # - No error message - # - No `exit()` - # - Re-raise to allow special, external CLI handling logic - raise ex + begin + # Copy args as Thor changes them within the call chain of dispatch() + _args = args.clone() + + # Call Thor's handlers as it does in start() + config[:shell] ||= Thor::Base.shell.new + dispatch(nil, args, nil, config) + + # Handle undefined commands at top-level and for `help ` + rescue Thor::UndefinedCommandError => ex + # Handle `help` for an argument that is not an application command such as `new` or `build` + if _args[0].downcase() == 'help' + + # Raise fatal StandardError to differentiate from UndefinedCommandError + msg = "Argument '#{_args[1]}' is not a recognized application command with detailed help. " + + "It may be a build / plugin task without detailed help or simply a goof." + raise( msg ) + + # Otherwise, eat unhandled command errors + else + # - No error message + # - No `exit()` + # - Re-raise to allow special, external CLI handling logic + raise ex + end end end end