Skip to content

Commit 14ed38f

Browse files
committed
feat: allow to define a description to the action
Add a user readable description in addition to the id Signed-off-by: Yves Brissaud <[email protected]>
1 parent 20f5dc5 commit 14ed38f

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

examples/alpine-hello.runx.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
actions:
22
- id: hello
3+
desc: Say hello to the current user
34
type: run
45
env:
56
- USER

internal/commands/root/root.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ func mdActions(rk *runkit.RunKit) string {
149149
s := strings.Builder{}
150150
s.WriteString("# Available actions\n\n")
151151
for _, action := range rk.Config.Actions {
152-
s.WriteString(fmt.Sprintf(" - `%s`\n", action.ID))
152+
if action.Desc != "" {
153+
s.WriteString(fmt.Sprintf(" - `%s`: %s\n", action.ID, action.Desc))
154+
} else {
155+
s.WriteString(fmt.Sprintf(" - `%s`\n", action.ID))
156+
}
153157
vars := "variable"
154158
if len(action.Env) > 1 {
155159
vars = p.Plural(vars)

internal/prompt/prompt.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/charmbracelet/huh"
77

88
"github.com/eunomie/docker-runx/internal/pizza"
9+
"github.com/eunomie/docker-runx/internal/sugar"
910
"github.com/eunomie/docker-runx/runkit"
1011
)
1112

@@ -17,7 +18,12 @@ func SelectAction(actions []runkit.Action) string {
1718
huh.NewSelect[string]().
1819
Title("Select the action to run").
1920
Options(pizza.Map[runkit.Action, huh.Option[string]](actions, func(action runkit.Action) huh.Option[string] {
20-
return huh.NewOption(action.ID+envStr(action.Env), action.ID)
21+
return huh.NewOption(
22+
sugar.If(action.Desc == "",
23+
action.ID,
24+
action.ID+": "+action.Desc,
25+
)+envStr(action.Env),
26+
action.ID)
2127
})...).
2228
Value(&action),
2329
),

internal/sugar/sugar.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package sugar
2+
3+
func If[T any](cond bool, a, b T) T {
4+
if cond {
5+
return a
6+
}
7+
return b
8+
}

runkit/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type (
1414

1515
Action struct {
1616
ID string `yaml:"id" json:"id"`
17+
Desc string `yaml:"desc,omitempty" json:"desc,omitempty"`
1718
Type ActionType `yaml:"type" json:"type"`
1819
Command string `yaml:"cmd" json:"cmd,omitempty"`
1920
Env []string `yaml:"env,omitempty" json:"env,omitempty"`

0 commit comments

Comments
 (0)