(socketPath *string)
| 12 | ) |
| 13 | |
| 14 | func (*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) |
no test coverage detected