Skip to content

Commit 4058dd7

Browse files
committed
allow new commands unknown to the CLI
1 parent d31f8f3 commit 4058dd7

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

internal/infra/run.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ var runCmds = map[model.RunCommand]string{
3939
model.UpdateGraphCommand: "bin/run fetch_files && bin/run update_graph",
4040
}
4141

42+
func updaterCommand(command model.RunCommand) string {
43+
if cmd, ok := runCmds[command]; ok {
44+
return cmd
45+
}
46+
return "bin/run"
47+
}
48+
4249
type RunParams struct {
4350
// Input file
4451
Input string
@@ -482,7 +489,7 @@ func runContainers(ctx context.Context, params RunParams) (err error) {
482489
if params.Flamegraph {
483490
env = append(env, "FLAMEGRAPH=1")
484491
}
485-
if err := updater.RunCmd(ctx, runCmds[params.Job.Command], dependabot, env...); err != nil {
492+
if err := updater.RunCmd(ctx, updaterCommand(params.Job.Command), dependabot, env...); err != nil {
486493
return err
487494
}
488495
if params.Flamegraph {

internal/infra/run_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,23 @@ func Test_generateIgnoreConditions(t *testing.T) {
246246
}
247247
})
248248
}
249+
250+
func Test_updaterCommand(t *testing.T) {
251+
tests := []struct {
252+
name string
253+
command model.RunCommand
254+
expected string
255+
}{
256+
{"update", model.UpdateFilesCommand, "bin/run fetch_files && bin/run update_files"},
257+
{"graph", model.UpdateGraphCommand, "bin/run fetch_files && bin/run update_graph"},
258+
{"unmapped command falls through to a bare bin/run", "reachability", "bin/run"},
259+
{"unrecognized command is never a no-op", "not-a-real-command", "bin/run"},
260+
}
261+
for _, tt := range tests {
262+
t.Run(tt.name, func(t *testing.T) {
263+
if got := updaterCommand(tt.command); got != tt.expected {
264+
t.Errorf("expected %q, got %q", tt.expected, got)
265+
}
266+
})
267+
}
268+
}

0 commit comments

Comments
 (0)