From 71e9caf0bca844b435c41c56f84f338ef870d734 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sun, 31 Jul 2022 02:15:42 -0700 Subject: [PATCH] Fix bug where help command doesn't show flags/subcommands --- cmd/itctl/main.go | 35 +++++++++++++++++++++++++++++++---- cmd/itgui/progress.go | 2 +- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/cmd/itctl/main.go b/cmd/itctl/main.go index 529a3e8..8a83e39 100644 --- a/cmd/itctl/main.go +++ b/cmd/itctl/main.go @@ -26,6 +26,7 @@ func main() { app := cli.App{ Name: "itctl", + HideHelpCommand: true, Flags: []cli.Flag{ &cli.StringFlag{ Name: "socket-path", @@ -35,6 +36,12 @@ func main() { }, }, Commands: []*cli.Command{ + { + Name: "help", + ArgsUsage: "", + Usage: "Display help screen for a command", + Action: helpCmd, + }, { Name: "filesystem", Aliases: []string{"fs"}, @@ -229,11 +236,13 @@ func main() { }, }, Before: func(c *cli.Context) error { - newClient, err := api.New(c.String("socket-path")) - if err != nil { - return err + if !isHelpCmd() { + newClient, err := api.New(c.String("socket-path")) + if err != nil { + return err + } + client = newClient } - client = newClient return nil }, After: func(*cli.Context) error { @@ -249,3 +258,21 @@ func main() { log.Fatal().Err(err).Msg("Error while running app") } } + +func helpCmd(c *cli.Context) error { + cmdArgs := append([]string{os.Args[0]}, c.Args().Slice()...) + cmdArgs = append(cmdArgs, "-h") + return c.App.RunContext(c.Context, cmdArgs) +} + +func isHelpCmd() bool { + if len(os.Args) == 1 { + return true + } + for _, arg := range os.Args { + if arg == "-h" || arg == "help" { + return true + } + } + return false +} \ No newline at end of file diff --git a/cmd/itgui/progress.go b/cmd/itgui/progress.go index c0261fd..fb717b7 100644 --- a/cmd/itgui/progress.go +++ b/cmd/itgui/progress.go @@ -29,7 +29,7 @@ func newProgress(w fyne.Window) progress { // Create new rectangle to set the size of the popup sizeRect := canvas.NewRectangle(color.Transparent) sizeRect.SetMinSize(fyne.NewSize(300, 50)) - + // Create vbox for label and progress bar l := container.NewVBox(out.lbl, out.pb) // Create popup