Skip to content

Commit 673aa7b

Browse files
committed
rofl/show: Support json format output
1 parent 8d241dc commit 673aa7b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cmd/rofl/mgmt.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,23 @@ var (
447447
appCfg, err := conn.Runtime(npa.ParaTime).ROFL.App(ctx, client.RoundLatest, appID)
448448
cobra.CheckErr(err)
449449

450+
replicas, err := conn.Runtime(npa.ParaTime).ROFL.AppInstances(ctx, client.RoundLatest, appID)
451+
cobra.CheckErr(err)
452+
453+
if common.OutputFormat() == common.FormatJSON {
454+
output := struct {
455+
App *rofl.AppConfig `json:"app"`
456+
Replicas []*rofl.Registration `json:"replicas"`
457+
}{
458+
App: appCfg,
459+
Replicas: replicas,
460+
}
461+
jsonOutput, err := common.PrettyJSONMarshal(output)
462+
cobra.CheckErr(err)
463+
fmt.Println(string(jsonOutput))
464+
return
465+
}
466+
450467
fmt.Printf("App ID: %s\n", appCfg.ID)
451468
fmt.Printf("Admin: ")
452469
switch appCfg.Admin {
@@ -479,9 +496,6 @@ var (
479496
fmt.Println()
480497
fmt.Printf("=== Replicas ===\n")
481498

482-
replicas, err := conn.Runtime(npa.ParaTime).ROFL.AppInstances(ctx, client.RoundLatest, appID)
483-
cobra.CheckErr(err)
484-
485499
if len(replicas) > 0 {
486500
for _, ai := range replicas {
487501
fmt.Printf("- RAK: %s\n", ai.RAK)
@@ -826,6 +840,7 @@ func init() {
826840

827841
showCmd.Flags().AddFlagSet(common.SelectorFlags)
828842
showCmd.Flags().AddFlagSet(roflCommon.DeploymentFlags)
843+
showCmd.Flags().AddFlagSet(common.FormatFlag)
829844

830845
secretSetCmd.Flags().AddFlagSet(roflCommon.DeploymentFlags)
831846
secretSetCmd.Flags().StringVar(&pubName, "public-name", "", "public secret name")

0 commit comments

Comments
 (0)