Skip to content

Commit a9170be

Browse files
committed
Use the parsed args
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent b471a0b commit a9170be

4 files changed

Lines changed: 7 additions & 38 deletions

File tree

cmd/root/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (f *runExecFlags) runRunCommand(cmd *cobra.Command, args []string) (command
145145
}
146146

147147
if f.sandbox {
148-
return runInSandbox(ctx, &f.runConfig, f.sandboxTemplate)
148+
return runInSandbox(ctx, args, &f.runConfig, f.sandboxTemplate)
149149
}
150150

151151
out := cli.NewPrinter(cmd.OutOrStdout())

cmd/root/sandbox.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
// runInSandbox delegates the current command to a Docker sandbox.
2121
// It ensures a sandbox exists (creating or recreating as needed), then
2222
// executes docker agent inside it via `docker sandbox exec`.
23-
func runInSandbox(ctx context.Context, runConfig *config.RuntimeConfig, template string) error {
23+
func runInSandbox(ctx context.Context, args []string, runConfig *config.RuntimeConfig, template string) error {
2424
if environment.InSandbox() {
2525
return fmt.Errorf("already running inside a Docker sandbox (VM %s)", os.Getenv("SANDBOX_VM_ID"))
2626
}
@@ -29,8 +29,12 @@ func runInSandbox(ctx context.Context, runConfig *config.RuntimeConfig, template
2929
return err
3030
}
3131

32+
var agentRef string
33+
if len(args) > 0 {
34+
agentRef = args[0]
35+
}
36+
3237
dockerAgentArgs := sandbox.BuildCagentArgs(os.Args)
33-
agentRef := sandbox.AgentRefFromArgs(dockerAgentArgs)
3438
configDir := paths.GetConfigDir()
3539

3640
// Always forward config directory paths so the sandbox-side

pkg/sandbox/args.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,6 @@ func isEqualsFormOf(arg string, flags map[string]bool) bool {
102102
return false
103103
}
104104

105-
// AgentRefFromArgs returns the first positional (non-flag) argument from the
106-
// docker-agent arg list, which is the agent file reference. Returns "" if there are
107-
// no positional arguments.
108-
func AgentRefFromArgs(args []string) string {
109-
for _, a := range args {
110-
if !strings.HasPrefix(a, "-") {
111-
return a
112-
}
113-
}
114-
return ""
115-
}
116-
117105
// ResolveAlias returns the alias path if name is a user-defined alias,
118106
// or an empty string otherwise.
119107
func ResolveAlias(name string) string {

pkg/sandbox/sandbox_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -244,29 +244,6 @@ func TestBuildCagentArgs_ResolvesAlias(t *testing.T) {
244244
assert.Equal(t, []string{"/path/to/dev.yaml", "--yolo"}, got)
245245
}
246246

247-
func TestAgentRefFromArgs(t *testing.T) {
248-
t.Parallel()
249-
250-
tests := []struct {
251-
name string
252-
args []string
253-
want string
254-
}{
255-
{"file first", []string{"./agent.yaml", "--debug"}, "./agent.yaml"},
256-
{"flags before file", []string{"--debug", "./agent.yaml"}, "./agent.yaml"},
257-
{"no positional", []string{"--debug", "--yolo"}, ""},
258-
{"empty", nil, ""},
259-
{"built-in name", []string{"default"}, "default"},
260-
}
261-
262-
for _, tt := range tests {
263-
t.Run(tt.name, func(t *testing.T) {
264-
t.Parallel()
265-
assert.Equal(t, tt.want, sandbox.AgentRefFromArgs(tt.args))
266-
})
267-
}
268-
}
269-
270247
func TestExtraWorkspace(t *testing.T) {
271248
tests := []struct {
272249
name string

0 commit comments

Comments
 (0)