Skip to content

Commit

Permalink
feat(cmd): add task selection
Browse files Browse the repository at this point in the history
  • Loading branch information
rektdeckard committed Sep 17, 2024
1 parent 33e4319 commit f3aba4c
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions cmd/lk/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,
},
},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f3aba4c

Please sign in to comment.