forked from Elara6331/itd
Fix bug where help command doesn't show flags/subcommands
This commit is contained in:
parent
5cd395a41b
commit
900be6f2d0
@ -26,6 +26,7 @@ func main() {
|
|||||||
|
|
||||||
app := cli.App{
|
app := cli.App{
|
||||||
Name: "itctl",
|
Name: "itctl",
|
||||||
|
HideHelpCommand: true,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "socket-path",
|
Name: "socket-path",
|
||||||
@ -35,6 +36,12 @@ func main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
|
{
|
||||||
|
Name: "help",
|
||||||
|
ArgsUsage: "<command>",
|
||||||
|
Usage: "Display help screen for a command",
|
||||||
|
Action: helpCmd,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "filesystem",
|
Name: "filesystem",
|
||||||
Aliases: []string{"fs"},
|
Aliases: []string{"fs"},
|
||||||
@ -229,11 +236,13 @@ func main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Before: func(c *cli.Context) error {
|
Before: func(c *cli.Context) error {
|
||||||
|
if !isHelpCmd() {
|
||||||
newClient, err := api.New(c.String("socket-path"))
|
newClient, err := api.New(c.String("socket-path"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
client = newClient
|
client = newClient
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
After: func(*cli.Context) error {
|
After: func(*cli.Context) error {
|
||||||
@ -249,3 +258,21 @@ func main() {
|
|||||||
log.Fatal().Err(err).Msg("Error while running app")
|
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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user