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

Method syncStatus

cli/sync_status.go:14–87  ·  view source on GitHub ↗
(socketPath *string)

Source from the content-addressed store, hash-verified

12)
13
14func (*RootCmd) syncStatus(socketPath *string) *serpent.Command {
15 formatter := cliui.NewOutputFormatter(
16 cliui.ChangeFormatterData(
17 cliui.TableFormat(
18 []agentsocket.DependencyInfo{},
19 []string{
20 "depends on",
21 "required status",
22 "current status",
23 "satisfied",
24 },
25 ),
26 func(data any) (any, error) {
27 resp, ok := data.(agentsocket.SyncStatusResponse)
28 if !ok {
29 return nil, xerrors.Errorf("expected agentsocket.SyncStatusResponse, got %T", data)
30 }
31 return resp.Dependencies, nil
32 }),
33 cliui.JSONFormat(),
34 )
35
36 cmd := &serpent.Command{
37 Use: "status <unit>",
38 Short: "Show unit status and dependency state",
39 Long: "Show the current status of a unit, whether it is ready to start, and lists its dependencies. Shows which dependencies are satisfied and which are still pending. Supports multiple output formats.",
40 Handler: func(i *serpent.Invocation) error {
41 ctx := i.Context()
42
43 if len(i.Args) != 1 {
44 return xerrors.New("exactly one unit name is required")
45 }
46 unit := unit.ID(i.Args[0])
47
48 opts := []agentsocket.Option{}
49 if *socketPath != "" {
50 opts = append(opts, agentsocket.WithPath(*socketPath))
51 }
52
53 client, err := agentsocket.NewClient(ctx, opts...)
54 if err != nil {
55 return xerrors.Errorf("connect to agent socket: %w", err)
56 }
57 defer client.Close()
58
59 statusResp, err := client.SyncStatus(ctx, unit)
60 if err != nil {
61 return xerrors.Errorf("get status failed: %w", err)
62 }
63
64 var out string
65 header := fmt.Sprintf("Unit: %s\nStatus: %s\nReady: %t\n\nDependencies:\n", unit, statusResp.Status, statusResp.IsReady)
66 if formatter.FormatID() == "table" && len(statusResp.Dependencies) == 0 {
67 out = header + "No dependencies found"
68 } else {
69 out, err = formatter.Format(ctx, statusResp)
70 if err != nil {
71 return xerrors.Errorf("format status: %w", err)

Callers 1

syncCommandMethod · 0.95

Calls 15

CloseMethod · 0.95
SyncStatusMethod · 0.95
FormatIDMethod · 0.95
FormatMethod · 0.95
AttachOptionsMethod · 0.95
NewOutputFormatterFunction · 0.92
ChangeFormatterDataFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
IDTypeAlias · 0.92
WithPathFunction · 0.92
NewClientFunction · 0.92

Tested by

no test coverage detected