class Toys::StandardMiddleware::HandleUsageErrors
the short help string, and terminates execution with an error code.
this middleware intercepts execution and displays the error along with
as an unrecognized flag or an unfulfilled required argument, is detected,
This middleware handles the case of a usage error. If a usage error, such
#
def initialize(exit_code: nil, stream: $stderr, styled_output: nil)
- 
        styled_output(Boolean, nil) -- Cause the tool to display help text
- 
        stream(IO) -- Output stream to write to. Default is stderr.
- 
        exit_code(Integer) -- The exit code to return if a usage error
def initialize(exit_code: nil, stream: $stderr, styled_output: nil) @exit_code = exit_code || USAGE_ERROR_EXIT_CODE @stream = stream @styled_output = styled_output end
def run(context)
- Private:   -   
def run(context) yield rescue ArgParsingError => e require "toys/utils/terminal" require "toys/utils/help_text" help_text = Utils::HelpText.from_context(context) terminal = Utils::Terminal.new(output: @stream, styled: @styled_output) terminal.puts(e.usage_errors.join("\n"), :bright_red, :bold) terminal.puts("") terminal.puts(help_text.usage_string(wrap_width: terminal.width)) Context.exit(@exit_code) end