From f3aba4c94f4a314a4d8f0648da52bd73476d9b2c Mon Sep 17 00:00:00 2001 From: rektdeckard Date: Mon, 16 Sep 2024 18:29:51 -0600 Subject: [PATCH] feat(cmd): add task selection --- cmd/lk/app.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/lk/app.go b/cmd/lk/app.go index 55a65b54..db426a44 100644 --- a/cmd/lk/app.go +++ b/cmd/lk/app.go @@ -88,7 +88,7 @@ var ( { Name: "install", Usage: "Execute installation defined in " + bootstrap.TaskFile, - ArgsUsage: "`DIR` location or the project directory (default: current directory)", + ArgsUsage: "`[DIR]` location of the project directory (default: current directory)", Before: requireProject, Action: installTemplate, }, @@ -103,7 +103,7 @@ var ( { Name: "run", Usage: "Execute a task defined in " + bootstrap.TaskFile, - ArgsUsage: "`DIR` location or the project directory (default: current directory)", + ArgsUsage: "`[TASK]` to run in the project's taskfile.yaml", Action: runTask, }, }, @@ -375,17 +375,29 @@ func doInstall(ctx context.Context, task bootstrap.KnownTask, rootPath string, v func runTask(ctx context.Context, cmd *cli.Command) error { verbose := cmd.Bool("verbose") - taskName := cmd.Args().First() - if taskName == "" { - return errors.New("task name is required") - } - rootDir := "." tf, err := bootstrap.ParseTaskfile(rootDir) if err != nil { return err } + taskName := cmd.Args().First() + if taskName == "" { + var options []huh.Option[string] + for _, name := range tf.Tasks.Keys() { + options = append(options, huh.NewOption(name, name)) + } + + if err := huh.NewSelect[string](). + Title("Select Task"). + Options(options...). + Value(&taskName). + WithTheme(theme). + Run(); err != nil { + return err + } + } + task, err := bootstrap.NewTask(ctx, tf, rootDir, taskName, cmd.Bool("verbose")) if err != nil { return err