MCPcopy Index your code
hub / github.com/coder/coder / syncWant

Method syncWant

cli/sync_want.go:15–52  ·  view source on GitHub ↗
(socketPath *string)

Source from the content-addressed store, hash-verified

13)
14
15func (*RootCmd) syncWant(socketPath *string) *serpent.Command {
16 cmd := &serpent.Command{
17 Use: "want <unit> <depends-on> [depends-on...]",
18 Short: "Declare that a unit depends on other units completing before it can start",
19 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.",
20 Handler: func(i *serpent.Invocation) error {
21 ctx := i.Context()
22
23 if len(i.Args) < 2 {
24 return xerrors.New("at least two arguments are required: unit and one or more depends-on")
25 }
26 dependentUnit := unit.ID(i.Args[0])
27
28 opts := []agentsocket.Option{}
29 if *socketPath != "" {
30 opts = append(opts, agentsocket.WithPath(*socketPath))
31 }
32
33 client, err := agentsocket.NewClient(ctx, opts...)
34 if err != nil {
35 return xerrors.Errorf("connect to agent socket: %w", err)
36 }
37 defer client.Close()
38
39 for _, dep := range i.Args[1:] {
40 if err := client.SyncWant(ctx, dependentUnit, unit.ID(dep)); err != nil {
41 return xerrors.Errorf("declare dependency failed: %w", err)
42 }
43 }
44
45 cliui.Info(i.Stdout, fmt.Sprintf("Unit %q declared dependencies: [%s]", dependentUnit, strings.Join(i.Args[1:], ", ")))
46
47 return nil
48 },
49 }
50
51 return cmd
52}

Callers 1

syncCommandMethod · 0.95

Calls 9

CloseMethod · 0.95
SyncWantMethod · 0.95
IDTypeAlias · 0.92
WithPathFunction · 0.92
NewClientFunction · 0.92
InfoFunction · 0.92
ContextMethod · 0.65
NewMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected