From 3b382b974750d0c705ad8062879d3a737e763f20 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Tue, 10 Oct 2023 12:59:43 -0700 Subject: [PATCH] Add the ability to list helper commands --- helper.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/helper.go b/helper.go index cdfdbe4..b38731d 100644 --- a/helper.go +++ b/helper.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "os" "strings" @@ -14,8 +15,10 @@ import ( ) var helperCmd = &cli.Command{ - Name: "helper", - Usage: "Run a lure helper command", + Name: "helper", + Usage: "Run a lure helper command", + ArgsUsage: ``, + Subcommands: []*cli.Command{helperListCmd}, Flags: []cli.Flag{ &cli.StringFlag{ Name: "dest-dir", @@ -28,6 +31,10 @@ var helperCmd = &cli.Command{ ctx := c.Context log := loggerctx.From(ctx) + if c.Args().Len() < 1 { + cli.ShowSubcommandHelpAndExit(c, 1) + } + wd, err := os.Getwd() if err != nil { log.Fatal("Error getting working directory").Err(err).Send() @@ -58,4 +65,22 @@ var helperCmd = &cli.Command{ return helper(hc, c.Args().First(), c.Args().Slice()[1:]) }, + CustomHelpTemplate: cli.CommandHelpTemplate, + BashComplete: func(ctx *cli.Context) { + for name := range helpers.Helpers { + fmt.Println(name) + } + }, +} + +var helperListCmd = &cli.Command{ + Name: "list", + Usage: "List all the available helper commands", + Aliases: []string{"ls"}, + Action: func(ctx *cli.Context) error { + for name := range helpers.Helpers { + fmt.Println(name) + } + return nil + }, }