Skip to content

Commit 72b3fbd

Browse files
[SAN-331] rename render ea sandbox to render ea sandboxes (#530)
* cmd: add routing tests for sandboxes rename * cmd: rename sandbox parent command to sandboxes * cmd: error on unknown ea subcommands Removing the sandbox command does not by itself make `render ea sandbox` fail. Cobra reports unknown commands only for the root; a nested parent like ea otherwise falls through to printing its help with a zero exit. Add cobra.NoArgs plus a help RunE so ea rejects any unknown subcommand, including the removed singular sandbox form, with a non-zero exit. The routing test drops --help because the help flag short-circuits arg validation. * cmd: update sandbox examples to plural form GitOrigin-RevId: c3b3439f3505494b8a23769d4afbc9aaaf90c954
1 parent ebd1915 commit 72b3fbd

7 files changed

Lines changed: 106 additions & 19 deletions

File tree

cmd/earlyaccess.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ func newEarlyAccessCmd() *cobra.Command {
1313
Long: `These commands are in early access and are subject to change.`,
1414
Example: ` # List early access object storage resources
1515
render ea objects list --region=oregon`,
16+
// Reject unknown subcommands with a non-zero exit. Cobra flags unknown
17+
// commands only for the root, so a nested parent needs NoArgs, plus a
18+
// RunE so arg validation runs (it also shows help for a bare "render ea").
19+
Args: cobra.NoArgs,
20+
RunE: func(cmd *cobra.Command, _ []string) error {
21+
return cmd.Help()
22+
},
1623
}
1724
}
1825

cmd/sandbox.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
func newSandboxCmd(children ...*cobra.Command) *cobra.Command {
88
cmd := &cobra.Command{
9-
Use: "sandbox",
9+
Use: "sandboxes",
1010
Short: "Manage sandboxes",
1111
Long: `Manage sandboxes for your Render workspace.
1212
@@ -19,11 +19,11 @@ Available commands:
1919
stop - Terminate a running sandbox
2020
2121
Examples:
22-
render ea sandbox create --base=render/sandbox-python
23-
render ea sandbox exec sbx-abc123 -- echo hello
24-
render ea sandbox list
25-
render ea sandbox list --all
26-
render ea sandbox stop trn-abc123 --confirm
22+
render ea sandboxes create --base=render/sandbox-python
23+
render ea sandboxes exec sbx-abc123 -- echo hello
24+
render ea sandboxes list
25+
render ea sandboxes list --all
26+
render ea sandboxes stop trn-abc123 --confirm
2727
`,
2828
}
2929
cmd.AddCommand(children...)

cmd/sandbox_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
10+
renderapi "github.com/render-oss/cli/internal/fakes/renderapi"
11+
"github.com/render-oss/cli/pkg/client"
12+
"github.com/render-oss/cli/pkg/command"
13+
"github.com/render-oss/cli/pkg/dependencies"
14+
)
15+
16+
// executeSandboxCommand runs the CLI with the sandbox tree registered under
17+
// ea, mirroring executeSandboxGroupsCommand in sandboxgroups_test.go.
18+
func executeSandboxCommand(t *testing.T, server *renderapi.Server, args ...string) (CommandResult, error) {
19+
t.Helper()
20+
t.Setenv("RENDER_CLI_CONFIG_PATH", newTestConfigPath(t))
21+
t.Setenv("RENDER_API_KEY", "test-api-key")
22+
23+
c, err := client.NewClientWithResponses(server.URL())
24+
require.NoError(t, err)
25+
deps := dependencies.New(c)
26+
deps.DetectRuntimeSignals = func() (command.RuntimeSignals, error) {
27+
return command.RuntimeSignals{StdinTTY: false, StdoutTTY: false, StderrTTY: false}, nil
28+
}
29+
30+
root := newRootCmd()
31+
ea := newEarlyAccessCmd()
32+
root.AddCommand(ea)
33+
setupSandboxCommands(ea, deps)
34+
setupRootCmdPersistentRun(root, deps)
35+
36+
var stdout, stderr bytes.Buffer
37+
root.SetOut(&stdout)
38+
root.SetErr(&stderr)
39+
root.SetArgs(args)
40+
41+
execErr := root.Execute()
42+
return CommandResult{Stdout: stdout.String(), Stderr: stderr.String()}, execErr
43+
}
44+
45+
// The parent command is plural per the PRD CLI spec and STYLE.md's
46+
// plural-resource rule.
47+
func TestSandboxes_PluralCommandResolves(t *testing.T) {
48+
server := renderapi.NewServer(t)
49+
50+
result, err := executeSandboxCommand(t, server, "ea", "sandboxes", "--help")
51+
require.NoError(t, err)
52+
assert.Contains(t, result.Stdout, "Manage sandboxes")
53+
assert.Contains(t, result.Stdout, "render ea sandboxes")
54+
}
55+
56+
// The singular form is removed outright (no alias), per the #sandboxes-core
57+
// decision that pre-alpha backwards compatibility is not needed. This test
58+
// locks that in: if someone reintroduces "sandbox" as a name or alias, this
59+
// fails and forces a deliberate decision.
60+
//
61+
// No --help here on purpose: the help flag short-circuits before Cobra
62+
// validates args, so "ea sandbox --help" would print ea's help with no error.
63+
// The unknown-command error comes from ea's cobra.NoArgs validator.
64+
func TestSandboxes_SingularFormRemoved(t *testing.T) {
65+
server := renderapi.NewServer(t)
66+
67+
_, err := executeSandboxCommand(t, server, "ea", "sandbox")
68+
require.Error(t, err)
69+
assert.Contains(t, err.Error(), "unknown command")
70+
}
71+
72+
func TestSandboxes_HelpListsSubcommands(t *testing.T) {
73+
server := renderapi.NewServer(t)
74+
75+
result, err := executeSandboxCommand(t, server, "ea", "sandboxes", "--help")
76+
require.NoError(t, err)
77+
for _, sub := range []string{"create", "exec", "list", "stop"} {
78+
assert.Contains(t, result.Stdout, sub, "expected subcommand %q in help output", sub)
79+
}
80+
}

cmd/sandboxcreate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ func newSandboxCreateCmd(deps *dependencies.Dependencies) *cobra.Command {
4848
Long: `Create a new sandbox in the current workspace.
4949
5050
Examples:
51-
render ea sandbox create
52-
render ea sandbox create --plan=standard --region=oregon
53-
render ea sandbox create --timeout=3600
51+
render ea sandboxes create
52+
render ea sandboxes create --plan=standard --region=oregon
53+
render ea sandboxes create --timeout=3600
5454
`,
5555
}
5656

cmd/sandboxexec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ Pass the command after a "--" separator so its own flags aren't parsed by the
4343
CLI.
4444
4545
Examples:
46-
render ea sandbox exec sbx-abc123 -- echo hello
47-
render ea sandbox exec sbx-abc123 -- python script.py
46+
render ea sandboxes exec sbx-abc123 -- echo hello
47+
render ea sandboxes exec sbx-abc123 -- python script.py
4848
`,
4949
Args: cobra.MinimumNArgs(2),
5050
}

cmd/sandboxlist.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ func newSandboxListCmd(deps *dependencies.Dependencies) *cobra.Command {
2323
By default, terminated sandboxes are excluded. Use --all to include them, or --status to filter by specific statuses.
2424
2525
Examples:
26-
render ea sandbox list
27-
render ea sandbox list --all
28-
render ea sandbox list --status=running
29-
render ea sandbox list --status=running --status=creating
30-
render ea sandbox list -o json
26+
render ea sandboxes list
27+
render ea sandboxes list --all
28+
render ea sandboxes list --status=running
29+
render ea sandboxes list --status=running --status=creating
30+
render ea sandboxes list -o json
3131
`,
3232
}
3333

cmd/sandboxstop.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ func newSandboxStopCmd(deps *dependencies.Dependencies) *cobra.Command {
3333
Without --confirm, this command previews what would be terminated and makes no
3434
changes. Pass --confirm to actually terminate the sandbox.`,
3535
Example: ` # Preview termination (no changes made)
36-
render ea sandbox stop trn-abc123
36+
render ea sandboxes stop trn-abc123
3737
3838
# Terminate the sandbox
39-
render ea sandbox stop trn-abc123 --confirm
39+
render ea sandboxes stop trn-abc123 --confirm
4040
4141
# JSON output
42-
render ea sandbox stop trn-abc123 --confirm --output json`,
42+
render ea sandboxes stop trn-abc123 --confirm --output json`,
4343
}
4444

4545
cmd.RunE = func(cmd *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)