()
| 79 | } |
| 80 | |
| 81 | func (r *RootCmd) ping() *serpent.Command { |
| 82 | var ( |
| 83 | pingNum int64 |
| 84 | pingTimeout time.Duration |
| 85 | pingWait time.Duration |
| 86 | pingTimeLocal bool |
| 87 | pingTimeUTC bool |
| 88 | ) |
| 89 | |
| 90 | cmd := &serpent.Command{ |
| 91 | Annotations: workspaceCommand, |
| 92 | Use: "ping <workspace>", |
| 93 | Short: "Ping a workspace", |
| 94 | Middleware: serpent.Chain( |
| 95 | serpent.RequireNArgs(1), |
| 96 | ), |
| 97 | Handler: func(inv *serpent.Invocation) error { |
| 98 | client, err := r.InitClient(inv) |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | ctx, cancel := context.WithCancel(inv.Context()) |
| 103 | defer cancel() |
| 104 | appearanceConfig := initAppearance(ctx, client) |
| 105 | notifyCtx, notifyCancel := inv.SignalNotifyContext(ctx, StopSignals...) |
| 106 | defer notifyCancel() |
| 107 | |
| 108 | workspaceName := inv.Args[0] |
| 109 | _, workspaceAgent, _, err := GetWorkspaceAndAgent( |
| 110 | ctx, inv, client, |
| 111 | false, // Do not autostart for a ping. |
| 112 | workspaceName, |
| 113 | ) |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | |
| 118 | // Start spinner after any build logs have finished streaming |
| 119 | spin := spinner.New(spinner.CharSets[5], 100*time.Millisecond) |
| 120 | spin.Writer = inv.Stderr |
| 121 | spin.Suffix = pretty.Sprint(cliui.DefaultStyles.Keyword, " Collecting diagnostics...") |
| 122 | if !r.verbose { |
| 123 | spin.Start() |
| 124 | } |
| 125 | |
| 126 | opts := &workspacesdk.DialAgentOptions{} |
| 127 | |
| 128 | if r.verbose { |
| 129 | opts.Logger = inv.Logger.AppendSinks(sloghuman.Sink(inv.Stdout)).Leveled(slog.LevelDebug) |
| 130 | } |
| 131 | |
| 132 | if r.disableDirect { |
| 133 | opts.BlockEndpoints = true |
| 134 | } |
| 135 | if !r.disableNetworkTelemetry { |
| 136 | opts.EnableTelemetry = true |
| 137 | } |
| 138 | wsClient := workspacesdk.New(client) |
no test coverage detected