From 9c601206e47d0ee9aafd073671b90348db15af43 Mon Sep 17 00:00:00 2001 From: Michael Karlesky Date: Tue, 27 Aug 2024 23:09:28 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Traditional=20begin=20/=20rescue?= =?UTF-8?q?=20instead=20of=20concise?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli.rb | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) 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