From 22b7b2b95312bee21f35ea10b351c29fadd1c439 Mon Sep 17 00:00:00 2001 From: John Guo Date: Sun, 21 Nov 2021 22:38:47 +0800 Subject: [PATCH] comment updates for package gcmd --- os/gcmd/gcmd_command_help.go | 4 ++-- os/gcmd/gcmd_command_run.go | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/os/gcmd/gcmd_command_help.go b/os/gcmd/gcmd_command_help.go index 72335c4df..1e482650e 100644 --- a/os/gcmd/gcmd_command_help.go +++ b/os/gcmd/gcmd_command_help.go @@ -114,14 +114,14 @@ func (c *Command) Print() { buffer.WriteString(gstr.WordWrap(gstr.Trim(c.Description), maxLineChars, "\n"+prefix)) buffer.WriteString("\n") } - buffer.WriteString("\n") // Additional. if c.Additional != "" { lineStr := gstr.WordWrap(gstr.Trim(c.Additional), maxLineChars, "\n") buffer.WriteString(lineStr) + buffer.WriteString("\n") } - buffer.WriteString("\n") + fmt.Println(buffer.String()) } diff --git a/os/gcmd/gcmd_command_run.go b/os/gcmd/gcmd_command_run.go index 0f412ad33..391cf3c15 100644 --- a/os/gcmd/gcmd_command_run.go +++ b/os/gcmd/gcmd_command_run.go @@ -10,6 +10,7 @@ package gcmd import ( "context" "fmt" + "os" "github.com/gogf/gf/v2/text/gstr" ) @@ -38,7 +39,11 @@ func (c *Command) Run(ctx context.Context) error { } // Print error and help command if no command found. - fmt.Printf("Error: command not found for \"%s\"\n\n", gstr.Join(args, " ")) + fmt.Printf( + "ERROR: command \"%s\" not found for arguments \"%s\"\n", + gstr.Join(args, " "), + gstr.Join(os.Args, " "), + ) c.Print() return nil @@ -63,6 +68,7 @@ func (c *Command) doRun(ctx context.Context, parser *Parser) (err error) { return c.Func(ctx, parser) } +// reParse re-parses the arguments using option configuration of current command. func (c *Command) reParse(ctx context.Context, parser *Parser) (*Parser, error) { // It seems just has built-in help option, it so does nothing. if len(c.Options) == 1 { @@ -83,6 +89,7 @@ func (c *Command) reParse(ctx context.Context, parser *Parser) (*Parser, error) return Parse(supportedOptions) } +// searchCommand recursively searches the command according given arguments. func (c *Command) searchCommand(args []string) *Command { if len(args) == 0 { return nil