Skip to content

Commit 677ce02

Browse files
authored
[devbox] add hidden all command to list all sub-commands (including hidden) (#901)
## Summary This provides a "single view" listing of all available commands. Sometimes I find myself wanting a global view to quickly find something. credit to chatgpt for writing some of this. Its a hidden command, since the printed view is not polished. ## How was it tested? ``` ❯ devbox all devbox Instant, easy, predictable development environments add <pkg>... Add a new package to your devbox all List all commands, including hidden ones cloud [Preview] Remote development environments on the cloud forward <local-port>:<remote-port> | :<remote-port> | stop | list[Preview] Port forward a local port to a remote devbox cloud port list List all port forwards managed by devbox stop Stop all port forwards managed by devbox init Create a Cloud VM without connecting to its shell shell [Preview] Shell into a cloud environment that matches your local devbox environment completion Generate the autocompletion script for the specified shell bash Generate the autocompletion script for bash fish Generate the autocompletion script for fish powershell Generate the autocompletion script for powershell zsh Generate the autocompletion script for zsh gen-docs <path> [Internal] Generate documentation for the CLI generate Generate supporting files for your project debug devcontainer Generate Dockerfile and devcontainer.json files under .devcontainer/ directory direnv Generate a .envrc file that integrates direnv with this devbox project dockerfile Generate a Dockerfile that replicates devbox shell ssh-config Generate ssh config to connect to devbox cloud global Manage global devbox packages add <pkg>... Add a new global package list List global packages pull <file> | <url> Pull a global config from a file or URL rm <pkg>... Remove a global package shellenv Print shell commands that add global Devbox packages to your PATH help [command] Help about any command info <pkg> Display package info init [<dir>] Initialize a directory as a devbox project install Install all packages mentioned in devbox.json log <event-name> [<event-specific-args>] plan Preview the plan used to build your environment rm <pkg>... Remove a package from your devbox run [<script> | <cmd>]Run a script or command in a shell with access to your packages services Interact with devbox services ls List available services restart [service]...Restart service. If no service is specified, restarts all services start [service]... Start service. If no service is specified, starts all services stop [service]... Stop service. If no service is specified, stops all services up Starts process manager with all supported services setup Setup devbox dependencies nix Install Nix shell Start a new shell with access to your packages shellenv Print shell commands that add Devbox packages to your PATH version Print version information update Update devbox launcher and binary ```
1 parent af3fbcf commit 677ce02

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

internal/boxcli/root.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package boxcli
55

66
import (
77
"context"
8+
"fmt"
89
"io"
910
"os"
1011
"strings"
@@ -64,6 +65,17 @@ func RootCmd() *cobra.Command {
6465
// Internal commands
6566
command.AddCommand(genDocsCmd())
6667

68+
// Register the "all" command to list all commands, including hidden ones.
69+
// This makes debugging easier.
70+
command.AddCommand(&cobra.Command{
71+
Use: "all",
72+
Short: "List all commands, including hidden ones",
73+
Hidden: true,
74+
Run: func(cmd *cobra.Command, args []string) {
75+
listAllCommands(command, "")
76+
},
77+
})
78+
6779
command.PersistentFlags().BoolVarP(
6880
&flags.quiet, "quiet", "q", false, "suppresses logs")
6981
debugMiddleware.AttachToFlag(command.PersistentFlags(), "debug")
@@ -94,3 +106,13 @@ func Main() {
94106
code := Execute(context.Background(), os.Args[1:])
95107
os.Exit(code)
96108
}
109+
110+
func listAllCommands(cmd *cobra.Command, indent string) {
111+
// Print this command's name and description in table format with indentation
112+
fmt.Printf("%s%-20s%s\n", indent, cmd.Use, cmd.Short)
113+
114+
// Recursively list child commands with increased indentation
115+
for _, childCmd := range cmd.Commands() {
116+
listAllCommands(childCmd, indent+"\t")
117+
}
118+
}

0 commit comments

Comments
 (0)