diff --git a/examples/alpine-hello.runx.yaml b/examples/alpine-hello.runx.yaml index 831efa6..882bc35 100644 --- a/examples/alpine-hello.runx.yaml +++ b/examples/alpine-hello.runx.yaml @@ -1,5 +1,6 @@ actions: - id: hello + desc: Say hello to the current user type: run env: - USER diff --git a/internal/commands/root/root.go b/internal/commands/root/root.go index 4915022..43d64de 100644 --- a/internal/commands/root/root.go +++ b/internal/commands/root/root.go @@ -149,7 +149,11 @@ func mdActions(rk *runkit.RunKit) string { s := strings.Builder{} s.WriteString("# Available actions\n\n") for _, action := range rk.Config.Actions { - s.WriteString(fmt.Sprintf(" - `%s`\n", action.ID)) + if action.Desc != "" { + s.WriteString(fmt.Sprintf(" - `%s`: %s\n", action.ID, action.Desc)) + } else { + s.WriteString(fmt.Sprintf(" - `%s`\n", action.ID)) + } vars := "variable" if len(action.Env) > 1 { vars = p.Plural(vars) diff --git a/internal/prompt/prompt.go b/internal/prompt/prompt.go index 0b3ce1a..8c356e1 100644 --- a/internal/prompt/prompt.go +++ b/internal/prompt/prompt.go @@ -6,6 +6,7 @@ import ( "github.com/charmbracelet/huh" "github.com/eunomie/docker-runx/internal/pizza" + "github.com/eunomie/docker-runx/internal/sugar" "github.com/eunomie/docker-runx/runkit" ) @@ -17,7 +18,12 @@ func SelectAction(actions []runkit.Action) string { huh.NewSelect[string](). Title("Select the action to run"). Options(pizza.Map[runkit.Action, huh.Option[string]](actions, func(action runkit.Action) huh.Option[string] { - return huh.NewOption(action.ID+envStr(action.Env), action.ID) + return huh.NewOption( + sugar.If(action.Desc == "", + action.ID, + action.ID+": "+action.Desc, + )+envStr(action.Env), + action.ID) })...). Value(&action), ), diff --git a/internal/sugar/sugar.go b/internal/sugar/sugar.go new file mode 100644 index 0000000..a9731d7 --- /dev/null +++ b/internal/sugar/sugar.go @@ -0,0 +1,8 @@ +package sugar + +func If[T any](cond bool, a, b T) T { + if cond { + return a + } + return b +} diff --git a/runkit/types.go b/runkit/types.go index 36acb1e..f769388 100644 --- a/runkit/types.go +++ b/runkit/types.go @@ -14,6 +14,7 @@ type ( Action struct { ID string `yaml:"id" json:"id"` + Desc string `yaml:"desc,omitempty" json:"desc,omitempty"` Type ActionType `yaml:"type" json:"type"` Command string `yaml:"cmd" json:"cmd,omitempty"` Env []string `yaml:"env,omitempty" json:"env,omitempty"`