Skip to content

Commit 560627b

Browse files
authored
feat: add list to devbox run if no args are given (#1054)
## Summary If merged this change will print available scripts if no arguments are given on the `devbox run` command. ## How was it tested? Trivial change, tested with CLI.
1 parent 712ba55 commit 560627b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

internal/boxcli/run.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package boxcli
55

66
import (
7+
"fmt"
8+
79
"github.com/spf13/cobra"
810

911
"go.jetpack.io/devbox"
@@ -28,7 +30,6 @@ func runCmd() *cobra.Command {
2830
Example: "\nRun a command directly:\n\n devbox add cowsay\n devbox run cowsay hello\n " +
2931
"devbox run -- cowsay -d hello\n\nRun a script (defined as `\"moo\": \"cowsay moo\"`) " +
3032
"in your devbox.json:\n\n devbox run moo",
31-
Args: cobra.MinimumNArgs(1),
3233
PreRunE: ensureNixInstalled,
3334
RunE: func(cmd *cobra.Command, args []string) error {
3435
return runScriptCmd(cmd, args, flags)
@@ -53,6 +54,19 @@ func listScripts(cmd *cobra.Command, flags runCmdFlags) []string {
5354
}
5455

5556
func runScriptCmd(cmd *cobra.Command, args []string, flags runCmdFlags) error {
57+
if len(args) == 0 {
58+
scripts := listScripts(cmd, flags)
59+
if len(scripts) == 0 {
60+
fmt.Fprintln(cmd.OutOrStdout(), "no scripts defined in devbox.json")
61+
return nil
62+
}
63+
fmt.Fprintln(cmd.OutOrStdout(), "Available scripts:")
64+
for _, p := range scripts {
65+
fmt.Fprintf(cmd.OutOrStdout(), "* %s\n", p)
66+
}
67+
return nil
68+
}
69+
5670
path, script, scriptArgs, err := parseScriptArgs(args, flags)
5771
if err != nil {
5872
return redact.Errorf("error parsing script arguments: %w", err)

0 commit comments

Comments
 (0)