From be0df90d053c005bde4ab7d3a1dcbfb75eb90546 Mon Sep 17 00:00:00 2001 From: John Guo Date: Thu, 25 Nov 2021 14:56:15 +0800 Subject: [PATCH] add strict attribute for gcmd.Command for strict option parsing --- os/gcmd/gcmd_command.go | 1 + os/gcmd/gcmd_command_run.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/os/gcmd/gcmd_command.go b/os/gcmd/gcmd_command.go index 234e30b2e..998129850 100644 --- a/os/gcmd/gcmd_command.go +++ b/os/gcmd/gcmd_command.go @@ -26,6 +26,7 @@ type Command struct { HelpFunc Function // Custom help function Examples string // Usage examples. Additional string // Additional info about this command, which will be appended to the end of help info. + Strict bool // Strict parsing options, which means it returns error if invalid option given. parent *Command // Parent command for internal usage. commands []Command // Sub commands of this command. } diff --git a/os/gcmd/gcmd_command_run.go b/os/gcmd/gcmd_command_run.go index 4236387d5..3f96a9fb6 100644 --- a/os/gcmd/gcmd_command_run.go +++ b/os/gcmd/gcmd_command_run.go @@ -97,7 +97,7 @@ func (c *Command) reParse(ctx context.Context, parser *Parser) (*Parser, error) } supportedOptions[optionKey] = !option.Orphan } - return Parse(supportedOptions) + return Parse(supportedOptions, c.Strict) } // searchCommand recursively searches the command according given arguments.