diff --git a/cli/sync_test.go b/cli/sync_test.go index a4578c4bb6..7635bab574 100644 --- a/cli/sync_test.go +++ b/cli/sync_test.go @@ -165,6 +165,37 @@ func TestSyncCommands_Golden(t *testing.T) { clitest.TestGoldenFile(t, "TestSyncCommands_Golden/want_success", outBuf.Bytes(), nil) }) + t.Run("want_multiple_deps", func(t *testing.T) { + t.Parallel() + path, cleanup := setupSocketServer(t) + defer cleanup() + + ctx := testutil.Context(t, testutil.WaitShort) + + var outBuf bytes.Buffer + inv, _ := clitest.New(t, "exp", "sync", "want", "test-unit", "dep-1", "dep-2", "dep-3", "--socket-path", path) + inv.Stdout = &outBuf + inv.Stderr = &outBuf + + err := inv.WithContext(ctx).Run() + require.NoError(t, err) + + // Verify all dependencies were registered by checking status. + outBuf.Reset() + inv, _ = clitest.New(t, "exp", "sync", "status", "test-unit", "--socket-path", path, "--output", "json") + inv.Stdout = &outBuf + inv.Stderr = &outBuf + + err = inv.WithContext(ctx).Run() + require.NoError(t, err) + + // The output should mention all three dependencies. + output := outBuf.String() + require.Contains(t, output, "dep-1") + require.Contains(t, output, "dep-2") + require.Contains(t, output, "dep-3") + }) + t.Run("complete", func(t *testing.T) { t.Parallel() path, cleanup := setupSocketServer(t) diff --git a/cli/sync_want.go b/cli/sync_want.go index 8bdc9b23a8..d6dde13d69 100644 --- a/cli/sync_want.go +++ b/cli/sync_want.go @@ -11,17 +11,16 @@ import ( func (*RootCmd) syncWant(socketPath *string) *serpent.Command { cmd := &serpent.Command{ - Use: "want ", - Short: "Declare that a unit depends on another unit completing before it can start", - Long: "Declare that a unit depends on another unit completing before it can start. The unit specified first will not start until the second has signaled that it has completed.", + Use: "want [depends-on...]", + Short: "Declare that a unit depends on other units completing before it can start", + Long: "Declare that a unit depends on one or more other units completing before it can start. The unit specified first will not start until all subsequent units have signaled that they have completed.", Handler: func(i *serpent.Invocation) error { ctx := i.Context() - if len(i.Args) != 2 { - return xerrors.New("exactly two arguments are required: unit and depends-on") + if len(i.Args) < 2 { + return xerrors.New("at least two arguments are required: unit and one or more depends-on") } dependentUnit := unit.ID(i.Args[0]) - dependsOn := unit.ID(i.Args[1]) opts := []agentsocket.Option{} if *socketPath != "" { @@ -34,8 +33,10 @@ func (*RootCmd) syncWant(socketPath *string) *serpent.Command { } defer client.Close() - if err := client.SyncWant(ctx, dependentUnit, dependsOn); err != nil { - return xerrors.Errorf("declare dependency failed: %w", err) + for _, dep := range i.Args[1:] { + if err := client.SyncWant(ctx, dependentUnit, unit.ID(dep)); err != nil { + return xerrors.Errorf("declare dependency failed: %w", err) + } } cliui.Info(i.Stdout, "Success") diff --git a/cli/testdata/coder_exp_sync_--help.golden b/cli/testdata/coder_exp_sync_--help.golden index b30447351c..4bb4e53c90 100644 --- a/cli/testdata/coder_exp_sync_--help.golden +++ b/cli/testdata/coder_exp_sync_--help.golden @@ -16,7 +16,7 @@ SUBCOMMANDS: ping Test agent socket connectivity and health start Wait until all unit dependencies are satisfied status Show unit status and dependency state - want Declare that a unit depends on another unit completing before it + want Declare that a unit depends on other units completing before it can start OPTIONS: diff --git a/cli/testdata/coder_exp_sync_want_--help.golden b/cli/testdata/coder_exp_sync_want_--help.golden index 0076f94ea9..a752f4aea6 100644 --- a/cli/testdata/coder_exp_sync_want_--help.golden +++ b/cli/testdata/coder_exp_sync_want_--help.golden @@ -1,13 +1,13 @@ coder v0.0.0-devel USAGE: - coder exp sync want + coder exp sync want [depends-on...] - Declare that a unit depends on another unit completing before it can start + Declare that a unit depends on other units completing before it can start - Declare that a unit depends on another unit completing before it can start. - The unit specified first will not start until the second has signaled that it - has completed. + Declare that a unit depends on one or more other units completing before it + can start. The unit specified first will not start until all subsequent units + have signaled that they have completed. ——— Run `coder --help` for a list of global options.