Skip to content

Commit

Permalink
Make structured/json output opt-in instead of opt-out.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Oct 30, 2023
1 parent 4dcb93d commit 6be6751
Show file tree
Hide file tree
Showing 40 changed files with 83 additions and 84 deletions.
1 change: 0 additions & 1 deletion cmd/state/internal/cmdtree/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,5 @@ func newActivateCommand(prime *primer.Values) *captain.Command {
},
)
cmd.SetGroup(EnvironmentUsageGroup)
cmd.SetDoesNotSupportStructuredOutput()
return cmd
}
6 changes: 3 additions & 3 deletions cmd/state/internal/cmdtree/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newAuthCommand(prime *primer.Values, globals *globalOptions) *captain.Comma
params.NonInteractive = globals.NonInteractive
return authRunner.Run(&params)
},
).SetGroup(PlatformGroup)
).SetGroup(PlatformGroup).SetSupportsStructuredOutput()
}

func newSignupCommand(prime *primer.Values) *captain.Command {
Expand All @@ -70,7 +70,7 @@ func newSignupCommand(prime *primer.Values) *captain.Command {
func(ccmd *captain.Command, args []string) error {
return signupRunner.Run(&params)
},
).SetDoesNotSupportStructuredOutput()
)
}

func newLogoutCommand(prime *primer.Values) *captain.Command {
Expand All @@ -85,5 +85,5 @@ func newLogoutCommand(prime *primer.Values) *captain.Command {
func(ccmd *captain.Command, args []string) error {
return logoutRunner.Run()
},
).SetDoesNotSupportStructuredOutput()
)
}
5 changes: 3 additions & 2 deletions cmd/state/internal/cmdtree/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func newBranchCommand(prime *primer.Values) *captain.Command {
[]*captain.Argument{},
func(_ *captain.Command, _ []string) error {
return runner.Run()
}).SetGroup(PlatformGroup).SetUnstable(true)
}).SetGroup(PlatformGroup).SetSupportsStructuredOutput().SetUnstable(true)
}

func newBranchAddCommand(prime *primer.Values) *captain.Command {
Expand All @@ -44,7 +44,7 @@ func newBranchAddCommand(prime *primer.Values) *captain.Command {
},
func(_ *captain.Command, _ []string) error {
return runner.Run(params)
})
}).SetSupportsStructuredOutput()
}

func newBranchSwitchCommand(prime *primer.Values) *captain.Command {
Expand All @@ -69,6 +69,7 @@ func newBranchSwitchCommand(prime *primer.Values) *captain.Command {
func(_ *captain.Command, _ []string) error {
return runner.Run(params)
})
cmd.SetSupportsStructuredOutput()
// We set this command to hidden for backwards compatibility as we cannot
// alias `state switch` to `state branch switch`
cmd.SetHidden(true)
Expand Down
8 changes: 4 additions & 4 deletions cmd/state/internal/cmdtree/bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func newBundlesCommand(prime *primer.Values) *captain.Command {
func(_ *captain.Command, _ []string) error {
return runner.Run(params, model.NamespaceBundle)
},
).SetGroup(PackagesGroup).SetUnstable(true)
).SetGroup(PackagesGroup).SetSupportsStructuredOutput().SetUnstable(true)
}

func newBundleInstallCommand(prime *primer.Values) *captain.Command {
Expand All @@ -64,7 +64,7 @@ func newBundleInstallCommand(prime *primer.Values) *captain.Command {
func(_ *captain.Command, _ []string) error {
return runner.Run(params, model.NamespaceBundle)
},
)
).SetSupportsStructuredOutput()
}

func newBundleUninstallCommand(prime *primer.Values) *captain.Command {
Expand All @@ -89,7 +89,7 @@ func newBundleUninstallCommand(prime *primer.Values) *captain.Command {
func(_ *captain.Command, _ []string) error {
return runner.Run(params, model.NamespaceBundle)
},
)
).SetSupportsStructuredOutput()
}

func newBundlesSearchCommand(prime *primer.Values) *captain.Command {
Expand Down Expand Up @@ -125,5 +125,5 @@ func newBundlesSearchCommand(prime *primer.Values) *captain.Command {
func(_ *captain.Command, _ []string) error {
return runner.Run(params, model.NamespaceBundle)
},
)
).SetSupportsStructuredOutput()
}
1 change: 1 addition & 0 deletions cmd/state/internal/cmdtree/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ func newCheckoutCommand(prime *primer.Values) *captain.Command {
},
)
cmd.SetGroup(EnvironmentSetupGroup)
cmd.SetSupportsStructuredOutput()
return cmd
}
8 changes: 4 additions & 4 deletions cmd/state/internal/cmdtree/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newCleanCommand(prime *primer.Values) *captain.Command {
prime.Output().Print(ccmd.Help())
return nil
},
).SetGroup(UtilsGroup)
).SetGroup(UtilsGroup).SetSupportsStructuredOutput()
}

func newCleanUninstallCommand(prime *primer.Values, globals *globalOptions) *captain.Command {
Expand Down Expand Up @@ -62,7 +62,7 @@ func newCleanUninstallCommand(prime *primer.Values, globals *globalOptions) *cap
params.NonInteractive = globals.NonInteractive // distinct from --force
return runner.Run(&params)
},
).SetDoesNotSupportStructuredOutput()
)
}

func newCleanCacheCommand(prime *primer.Values, globals *globalOptions) *captain.Command {
Expand All @@ -86,7 +86,7 @@ func newCleanCacheCommand(prime *primer.Values, globals *globalOptions) *captain
params.Force = globals.NonInteractive
return runner.Run(&params)
},
).SetDoesNotSupportStructuredOutput()
)
}

func newCleanConfigCommand(prime *primer.Values) *captain.Command {
Expand All @@ -109,5 +109,5 @@ func newCleanConfigCommand(prime *primer.Values) *captain.Command {
func(ccmd *captain.Command, _ []string) error {
return runner.Run(&params)
},
).SetDoesNotSupportStructuredOutput()
)
}
4 changes: 3 additions & 1 deletion cmd/state/internal/cmdtree/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func newCommitCommand(prime *primer.Values) *captain.Command {
},
)

cmd.SetGroup(EnvironmentSetupGroup).SetUnstable(true)
cmd.SetGroup(EnvironmentSetupGroup)
cmd.SetSupportsStructuredOutput()
cmd.SetUnstable(true)

return cmd
}
6 changes: 3 additions & 3 deletions cmd/state/internal/cmdtree/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func newConfigCommand(prime *primer.Values) *captain.Command {
return err
}
return runner.Run(ccmd.Usage)
}).SetGroup(UtilsGroup)
}).SetGroup(UtilsGroup).SetSupportsStructuredOutput()
}

func newConfigGetCommand(prime *primer.Values) *captain.Command {
Expand All @@ -43,7 +43,7 @@ func newConfigGetCommand(prime *primer.Values) *captain.Command {
func(ccmd *captain.Command, args []string) error {
runner := config.NewGet(prime)
return runner.Run(params)
})
}).SetSupportsStructuredOutput()
}

func newConfigSetCommand(prime *primer.Values) *captain.Command {
Expand Down Expand Up @@ -71,5 +71,5 @@ func newConfigSetCommand(prime *primer.Values) *captain.Command {
func(ccmd *captain.Command, args []string) error {
runner := config.NewSet(prime)
return runner.Run(params)
})
}).SetSupportsStructuredOutput()
}
5 changes: 3 additions & 2 deletions cmd/state/internal/cmdtree/cve.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func newCveCommand(prime *primer.Values) *captain.Command {
)
cmd.SetGroup(PlatformGroup)
cmd.SetAliases("cve")
cmd.SetSupportsStructuredOutput()
cmd.SetUnstable(true)
return cmd
}
Expand All @@ -50,7 +51,7 @@ func newReportCommand(prime *primer.Values) *captain.Command {
func(_ *captain.Command, _ []string) error {
return report.Run(&params)
},
)
).SetSupportsStructuredOutput()
}

func newOpenCommand(prime *primer.Values) *captain.Command {
Expand All @@ -73,5 +74,5 @@ func newOpenCommand(prime *primer.Values) *captain.Command {
func(_ *captain.Command, _ []string) error {
return open.Run(params)
},
).SetDoesNotSupportStructuredOutput()
)
}
11 changes: 5 additions & 6 deletions cmd/state/internal/cmdtree/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func newDeployCommand(prime *primer.Values) *captain.Command {
})
cmd.SetGroup(EnvironmentSetupGroup)
cmd.SetHidden(true)
cmd.SetDoesNotSupportStructuredOutput()
return cmd
}

Expand Down Expand Up @@ -85,7 +84,7 @@ func newDeployInstallCommand(prime *primer.Values) *captain.Command {
},
func(cmd *captain.Command, args []string) error {
return runner.Run(params)
}).SetDoesNotSupportStructuredOutput()
})
}

func newDeployConfigureCommand(prime *primer.Values) *captain.Command {
Expand Down Expand Up @@ -124,7 +123,7 @@ func newDeployConfigureCommand(prime *primer.Values) *captain.Command {
},
func(cmd *captain.Command, args []string) error {
return runner.Run(params)
}).SetDoesNotSupportStructuredOutput()
})
}

func newDeploySymlinkCommand(prime *primer.Values) *captain.Command {
Expand Down Expand Up @@ -159,7 +158,7 @@ func newDeploySymlinkCommand(prime *primer.Values) *captain.Command {
},
func(cmd *captain.Command, args []string) error {
return runner.Run(params)
}).SetDoesNotSupportStructuredOutput()
})
}

func newDeployReportCommand(prime *primer.Values) *captain.Command {
Expand Down Expand Up @@ -189,7 +188,7 @@ func newDeployReportCommand(prime *primer.Values) *captain.Command {
},
func(cmd *captain.Command, args []string) error {
return runner.Run(params)
}).SetDoesNotSupportStructuredOutput()
})
}

func newDeployUninstallCommand(prime *primer.Values) *captain.Command {
Expand Down Expand Up @@ -221,5 +220,5 @@ func newDeployUninstallCommand(prime *primer.Values) *captain.Command {
[]*captain.Argument{},
func(cmd *captain.Command, args []string) error {
return runner.Run(params)
}).SetDoesNotSupportStructuredOutput()
})
}
4 changes: 2 additions & 2 deletions cmd/state/internal/cmdtree/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newEventsCommand(prime *primer.Values) *captain.Command {
[]*captain.Argument{},
func(cmd *captain.Command, args []string) error {
return runner.Run()
}).SetGroup(AutomationGroup).SetUnstable(true)
}).SetGroup(AutomationGroup).SetSupportsStructuredOutput().SetUnstable(true)
}

func newEventsLogCommand(prime *primer.Values) *captain.Command {
Expand All @@ -42,5 +42,5 @@ func newEventsLogCommand(prime *primer.Values) *captain.Command {
[]*captain.Argument{},
func(cmd *captain.Command, args []string) error {
return runner.Run(&params)
}).SetDoesNotSupportStructuredOutput()
})
}
1 change: 0 additions & 1 deletion cmd/state/internal/cmdtree/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func newExecCommand(prime *primer.Values, args ...string) *captain.Command {

cmd.SetGroup(EnvironmentUsageGroup)
cmd.SetHasVariableArguments()
cmd.SetDoesNotSupportStructuredOutput()

return cmd
}
16 changes: 8 additions & 8 deletions cmd/state/internal/cmdtree/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func newExportCommand(prime *primer.Values) *captain.Command {
[]*captain.Argument{},
func(ccmd *captain.Command, args []string) error {
return runner.Run(ccmd)
}).SetGroup(UtilsGroup)
}).SetGroup(UtilsGroup).SetSupportsStructuredOutput()
}

func newRecipeCommand(prime *primer.Values) *captain.Command {
Expand Down Expand Up @@ -59,7 +59,7 @@ func newRecipeCommand(prime *primer.Values) *captain.Command {
},
func(_ *captain.Command, _ []string) error {
return recipe.Run(&params)
}).SetUnstable(true)
}).SetSupportsStructuredOutput().SetUnstable(true)
}

func newJWTCommand(prime *primer.Values) *captain.Command {
Expand All @@ -76,7 +76,7 @@ func newJWTCommand(prime *primer.Values) *captain.Command {
[]*captain.Argument{},
func(ccmd *captain.Command, args []string) error {
return jwt.Run(&params)
})
}).SetSupportsStructuredOutput()
}

func newPrivateKeyCommand(prime *primer.Values) *captain.Command {
Expand All @@ -93,7 +93,7 @@ func newPrivateKeyCommand(prime *primer.Values) *captain.Command {
[]*captain.Argument{},
func(ccmd *captain.Command, args []string) error {
return privateKey.Run(&params)
})
}).SetSupportsStructuredOutput()
}

func newAPIKeyCommand(prime *primer.Values) *captain.Command {
Expand All @@ -117,7 +117,7 @@ func newAPIKeyCommand(prime *primer.Values) *captain.Command {
func(ccmd *captain.Command, args []string) error {
params.IsAuthed = prime.Auth().Authenticated
return apikey.Run(params)
})
}).SetSupportsStructuredOutput()
}

func newExportConfigCommand(prime *primer.Values) *captain.Command {
Expand All @@ -142,7 +142,7 @@ func newExportConfigCommand(prime *primer.Values) *captain.Command {
[]*captain.Argument{},
func(ccmd *captain.Command, _ []string) error {
return runner.Run(ccmd, &params)
}).SetUnstable(true)
}).SetSupportsStructuredOutput().SetUnstable(true)
}

func newExportGithubActionCommand(prime *primer.Values) *captain.Command {
Expand All @@ -158,7 +158,7 @@ func newExportGithubActionCommand(prime *primer.Values) *captain.Command {
[]*captain.Argument{},
func(ccmd *captain.Command, _ []string) error {
return runner.Run(&params)
}).SetUnstable(true).SetDoesNotSupportStructuredOutput()
}).SetUnstable(true)
}

func newExportDocsCommand(prime *primer.Values) *captain.Command {
Expand All @@ -177,7 +177,6 @@ func newExportDocsCommand(prime *primer.Values) *captain.Command {
})

cmd.SetHidden(true)
cmd.SetDoesNotSupportStructuredOutput()

return cmd
}
Expand All @@ -196,6 +195,7 @@ func newExportEnvCommand(prime *primer.Values) *captain.Command {
return runner.Run()
})

cmd.SetSupportsStructuredOutput()
cmd.SetUnstable(true)

return cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/state/internal/cmdtree/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ func newForkCommand(prime *primer.Values) *captain.Command {
},
func(cmd *captain.Command, args []string) error {
return runner.Run(params)
}).SetGroup(VCSGroup)
}).SetGroup(VCSGroup).SetSupportsStructuredOutput()
}
2 changes: 2 additions & 0 deletions cmd/state/internal/cmdtree/hello_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func newHelloCommand(prime *primer.Values) *captain.Command {

// The group is used to group together commands in the --help output
cmd.SetGroup(UtilsGroup)
// Commands should support structured (JSON) output whenever possible.
cmd.SetSupportsStructuredOutput()
// Any new command should be marked unstable for the first release it goes out in.
cmd.SetUnstable(true)
// Certain commands like `state deploy` are there for backwards compatibility, but we don't want to show them in the --help output as they are not part of the happy path or our long term goals.
Expand Down
2 changes: 1 addition & 1 deletion cmd/state/internal/cmdtree/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ func newHistoryCommand(prime *primer.Values) *captain.Command {
func(ccmd *captain.Command, _ []string) error {
return initRunner.Run(&params)
},
).SetGroup(VCSGroup)
).SetGroup(VCSGroup).SetSupportsStructuredOutput()
}
2 changes: 1 addition & 1 deletion cmd/state/internal/cmdtree/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ func newInitCommand(prime *primer.Values) *captain.Command {
func(ccmd *captain.Command, _ []string) error {
return initRunner.Run(&params)
},
).SetGroup(EnvironmentSetupGroup)
).SetGroup(EnvironmentSetupGroup).SetSupportsStructuredOutput()
}
1 change: 0 additions & 1 deletion cmd/state/internal/cmdtree/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func newInviteCommand(prime *primer.Values) *captain.Command {
cmd.SetGroup(PlatformGroup)
cmd.SetUnstable(true)
cmd.SetHasVariableArguments()
cmd.SetDoesNotSupportStructuredOutput()

return cmd
}
Loading

0 comments on commit 6be6751

Please sign in to comment.