Skip to content

Commit de05818

Browse files
sjmiller609claude
andcommitted
Match output format conventions for new commands
Add human-readable default (auto) output for wait, auto-standby status, and snapshot schedule set/get commands, matching the pattern used by resources and reclaim-memory. JSON output remains available via --format json for scripting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 968fef8 commit de05818

3 files changed

Lines changed: 130 additions & 4 deletions

File tree

pkg/cmd/autostandbycmd.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,45 @@ func handleAutoStandbyStatus(ctx context.Context, cmd *cli.Command) error {
5757

5858
format := cmd.Root().String("format")
5959
transform := cmd.Root().String("transform")
60-
return ShowJSON(os.Stdout, "auto-standby status", gjson.ParseBytes(res), format, transform)
60+
61+
obj := gjson.ParseBytes(res)
62+
63+
if format == "auto" {
64+
status := obj.Get("status").String()
65+
enabled := obj.Get("enabled").Bool()
66+
configured := obj.Get("configured").Bool()
67+
supported := obj.Get("supported").Bool()
68+
idleTimeout := obj.Get("idle_timeout").String()
69+
reason := obj.Get("reason").String()
70+
trackingMode := obj.Get("tracking_mode").String()
71+
connections := obj.Get("active_inbound_connections").Int()
72+
73+
if idleTimeout == "" {
74+
idleTimeout = "-"
75+
}
76+
if reason == "" {
77+
reason = "-"
78+
}
79+
80+
fmt.Printf("%-14s %s\n", "STATUS", status)
81+
fmt.Printf("%-14s %t\n", "ENABLED", enabled)
82+
fmt.Printf("%-14s %t\n", "CONFIGURED", configured)
83+
fmt.Printf("%-14s %t\n", "SUPPORTED", supported)
84+
fmt.Printf("%-14s %s\n", "IDLE TIMEOUT", idleTimeout)
85+
fmt.Printf("%-14s %s\n", "REASON", reason)
86+
fmt.Printf("%-14s %s\n", "TRACKING", trackingMode)
87+
fmt.Printf("%-14s %d\n", "CONNECTIONS", connections)
88+
89+
if idleSince := obj.Get("idle_since").String(); idleSince != "" {
90+
fmt.Printf("%-14s %s\n", "IDLE SINCE", idleSince)
91+
}
92+
if nextStandby := obj.Get("next_standby_at").String(); nextStandby != "" {
93+
fmt.Printf("%-14s %s\n", "NEXT STANDBY", nextStandby)
94+
}
95+
return nil
96+
}
97+
98+
return ShowJSON(os.Stdout, "auto-standby status", obj, format, transform)
6199
}
62100

63101
func buildAutoStandbyPolicy(cmd *cli.Command, prefix string) (hypeman.AutoStandbyPolicyParam, bool, error) {

pkg/cmd/snapshotschedulecmd.go

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,15 @@ func handleSnapshotScheduleSet(ctx context.Context, cmd *cli.Command) error {
108108

109109
format := cmd.Root().String("format")
110110
transform := cmd.Root().String("transform")
111-
return ShowJSON(os.Stdout, "snapshot schedule set", gjson.ParseBytes(res), format, transform)
111+
112+
obj := gjson.ParseBytes(res)
113+
114+
if format == "auto" {
115+
printSnapshotScheduleSummary(obj)
116+
return nil
117+
}
118+
119+
return ShowJSON(os.Stdout, "snapshot schedule set", obj, format, transform)
112120
}
113121

114122
func handleSnapshotScheduleGet(ctx context.Context, cmd *cli.Command) error {
@@ -137,7 +145,15 @@ func handleSnapshotScheduleGet(ctx context.Context, cmd *cli.Command) error {
137145

138146
format := cmd.Root().String("format")
139147
transform := cmd.Root().String("transform")
140-
return ShowJSON(os.Stdout, "snapshot schedule get", gjson.ParseBytes(res), format, transform)
148+
149+
obj := gjson.ParseBytes(res)
150+
151+
if format == "auto" {
152+
printSnapshotScheduleSummary(obj)
153+
return nil
154+
}
155+
156+
return ShowJSON(os.Stdout, "snapshot schedule get", obj, format, transform)
141157
}
142158

143159
func handleSnapshotScheduleDelete(ctx context.Context, cmd *cli.Command) error {
@@ -192,3 +208,54 @@ func buildSnapshotScheduleRequest(cmd *cli.Command) (hypeman.SetSnapshotSchedule
192208

193209
return request, malformedMetadata, nil
194210
}
211+
212+
func printSnapshotScheduleSummary(obj gjson.Result) {
213+
instanceID := obj.Get("instance_id").String()
214+
interval := obj.Get("interval").String()
215+
maxAge := obj.Get("retention.max_age").String()
216+
maxCount := obj.Get("retention.max_count").Int()
217+
namePrefix := obj.Get("name_prefix").String()
218+
nextRun := obj.Get("next_run_at").String()
219+
createdAt := obj.Get("created_at").String()
220+
221+
if maxAge == "" {
222+
maxAge = "-"
223+
}
224+
if namePrefix == "" {
225+
namePrefix = "-"
226+
}
227+
if nextRun == "" {
228+
nextRun = "-"
229+
}
230+
231+
maxCountStr := "-"
232+
if maxCount > 0 {
233+
maxCountStr = fmt.Sprintf("%d", maxCount)
234+
}
235+
236+
fmt.Printf("%-14s %s\n", "INSTANCE", instanceID)
237+
fmt.Printf("%-14s %s\n", "INTERVAL", interval)
238+
fmt.Printf("%-14s %s\n", "MAX AGE", maxAge)
239+
fmt.Printf("%-14s %s\n", "MAX COUNT", maxCountStr)
240+
fmt.Printf("%-14s %s\n", "PREFIX", namePrefix)
241+
fmt.Printf("%-14s %s\n", "NEXT RUN", nextRun)
242+
fmt.Printf("%-14s %s\n", "CREATED", createdAt)
243+
244+
metadata := obj.Get("metadata")
245+
if metadata.Exists() && metadata.IsObject() {
246+
fmt.Printf("%-14s", "METADATA")
247+
first := true
248+
metadata.ForEach(func(key, value gjson.Result) bool {
249+
if first {
250+
fmt.Printf(" %s=%s\n", key.String(), value.String())
251+
first = false
252+
} else {
253+
fmt.Printf("%-14s %s=%s\n", "", key.String(), value.String())
254+
}
255+
return true
256+
})
257+
if first {
258+
fmt.Println(" -")
259+
}
260+
}
261+
}

pkg/cmd/wait.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,28 @@ func handleWait(ctx context.Context, cmd *cli.Command) error {
6969

7070
format := cmd.Root().String("format")
7171
transform := cmd.Root().String("transform")
72-
return ShowJSON(os.Stdout, "instance wait", gjson.ParseBytes(res), format, transform)
72+
73+
obj := gjson.ParseBytes(res)
74+
75+
if format == "auto" {
76+
state := obj.Get("state").String()
77+
timedOut := obj.Get("timed_out").Bool()
78+
stateError := obj.Get("state_error").String()
79+
80+
if timedOut {
81+
fmt.Fprintf(os.Stderr, "Timed out waiting (last state: %s)\n", state)
82+
return fmt.Errorf("timed out waiting for instance to reach state %s", cmd.String("state"))
83+
}
84+
if stateError != "" {
85+
fmt.Printf("%-14s %s\n", "STATE", state)
86+
fmt.Printf("%-14s %s\n", "STATE ERROR", stateError)
87+
} else {
88+
fmt.Println(state)
89+
}
90+
return nil
91+
}
92+
93+
return ShowJSON(os.Stdout, "instance wait", obj, format, transform)
7394
}
7495

7596
func parseInstanceWaitState(raw string) (hypeman.InstanceWaitParamsState, error) {

0 commit comments

Comments
 (0)