Skip to content

Commit 2265af8

Browse files
committed
feat: if no action, display docs
Signed-off-by: Yves Brissaud <[email protected]>
1 parent fb9c479 commit 2265af8

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

internal/commands/root/root.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ func NewCmd(dockerCli command.Cli, isPlugin bool) *cobra.Command {
9191
return err
9292
}
9393

94+
if action == "" && !list && !docs && len(rk.Config.Actions) == 0 {
95+
_, _ = fmt.Fprintln(dockerCli.Out(), tui.Markdown(rk.Readme))
96+
return nil
97+
}
98+
9499
if docs {
95100
_, _ = fmt.Fprintln(dockerCli.Out(), tui.Markdown(rk.Readme+"\n---\n"+mdActions(rk)))
96101
return nil
@@ -99,7 +104,7 @@ func NewCmd(dockerCli command.Cli, isPlugin bool) *cobra.Command {
99104
action = selectAction(action, lc.Images[src], rk.Config.Default)
100105

101106
if list || action == "" {
102-
if tui.IsATTY(dockerCli.In().FD()) {
107+
if tui.IsATTY(dockerCli.In().FD()) && len(rk.Config.Actions) > 0 {
103108
selectedAction := prompt.SelectAction(rk.Config.Actions)
104109
if selectedAction != "" {
105110
return run(cmd.Context(), dockerCli.Err(), src, rk, selectedAction)
@@ -232,18 +237,22 @@ func mdActions(rk *runkit.RunKit) string {
232237
p := pluralize.NewClient()
233238
s := strings.Builder{}
234239
s.WriteString("# Available actions\n\n")
235-
for _, action := range rk.Config.Actions {
236-
if action.Desc != "" {
237-
s.WriteString(fmt.Sprintf(" - `%s`: %s\n", action.ID, action.Desc))
238-
} else {
239-
s.WriteString(fmt.Sprintf(" - `%s`\n", action.ID))
240-
}
241-
vars := "variable"
242-
if len(action.Env) > 1 {
243-
vars = p.Plural(vars)
244-
}
245-
if len(action.Env) > 0 {
246-
s.WriteString(" - Environment " + vars + ": " + strings.Join(tui.BackQuoteItems(action.Env), ", ") + "\n")
240+
if len(rk.Config.Actions) == 0 {
241+
s.WriteString("> No available action\n")
242+
} else {
243+
for _, action := range rk.Config.Actions {
244+
if action.Desc != "" {
245+
s.WriteString(fmt.Sprintf(" - `%s`: %s\n", action.ID, action.Desc))
246+
} else {
247+
s.WriteString(fmt.Sprintf(" - `%s`\n", action.ID))
248+
}
249+
vars := "variable"
250+
if len(action.Env) > 1 {
251+
vars = p.Plural(vars)
252+
}
253+
if len(action.Env) > 0 {
254+
s.WriteString(" - Environment " + vars + ": " + strings.Join(tui.BackQuoteItems(action.Env), ", ") + "\n")
255+
}
247256
}
248257
}
249258

0 commit comments

Comments
 (0)