Skip to content

Commit 8c8aa17

Browse files
authored
feat: add scripts as valid args for shell completion (#775)
## Summary Add scripts in `devbox.json` as `devbox run`'s valid arguments and it provides shell completion. Here's the screenshot: <img width="825" alt="Screenshot 2023-03-16 at 21 45 20" src="https://user-images.githubusercontent.com/7611700/225638218-1915e62d-fec9-4ceb-9f73-b1072acde125.png"> And here's a demo: https://user-images.githubusercontent.com/7611700/225638325-e971c651-7383-4ddc-84db-861e6de4cbd2.mp4 ## How was it tested?
1 parent 25f57e3 commit 8c8aa17

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

internal/boxcli/args.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
// If args empty, defaults to the current directory
1616
// Otherwise grabs the path from the first argument
1717
func configPathFromUser(args []string, flags *configFlags) (string, error) {
18-
1918
if flags.path != "" && len(args) > 0 {
2019
return "", usererr.New(
2120
"Cannot specify devbox.json's path via both --config and the command arguments. " +

internal/boxcli/run.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,28 @@ func RunCmd() *cobra.Command {
3636

3737
flags.config.register(command)
3838

39+
command.ValidArgs = listScripts(command, flags)
40+
3941
return command
4042
}
4143

42-
func runScriptCmd(cmd *cobra.Command, args []string, flags runCmdFlags) error {
44+
func listScripts(cmd *cobra.Command, flags runCmdFlags) []string {
45+
path, err := configPathFromUser([]string{}, &flags.config)
46+
if err != nil {
47+
debug.Log("failed to get config path from user: %v", err)
48+
return nil
49+
}
50+
51+
box, err := devbox.Open(path, cmd.ErrOrStderr())
52+
if err != nil {
53+
debug.Log("failed to open devbox: %v", err)
54+
return nil
55+
}
4356

57+
return box.ListScripts()
58+
}
59+
60+
func runScriptCmd(cmd *cobra.Command, args []string, flags runCmdFlags) error {
4461
path, script, scriptArgs, err := parseScriptArgs(args, flags)
4562
if err != nil {
4663
return err

0 commit comments

Comments
 (0)