Skip to content

Commit

Permalink
Add --output flag to various commands
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Dec 19, 2023
1 parent a5ac031 commit 8db43f8
Show file tree
Hide file tree
Showing 48 changed files with 269 additions and 137 deletions.
3 changes: 2 additions & 1 deletion cli/cmd/app_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (r *runners) InitAppCreate(parent *cobra.Command) *cobra.Command {
SilenceUsage: true,
}
parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

return cmd
}
Expand Down Expand Up @@ -45,5 +46,5 @@ func (r *runners) createApp(_ *cobra.Command, args []string) error {
},
}

return print.Apps(r.w, apps)
return print.Apps(r.outputFormat, r.w, apps)
}
3 changes: 2 additions & 1 deletion cli/cmd/app_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (r *runners) InitAppDelete(parent *cobra.Command) *cobra.Command {
}
parent.AddCommand(cmd)
cmd.Flags().BoolVarP(&r.args.deleteAppForceYes, "force", "f", false, "Skip confirmation prompt. There is no undo for this action.")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

return cmd
}
Expand All @@ -40,7 +41,7 @@ func (r *runners) deleteApp(_ *cobra.Command, args []string) error {

apps := []types.AppAndChannels{{App: app}}

err = print.Apps(r.w, apps)
err = print.Apps(r.outputFormat, r.w, apps)
if err != nil {
return errors.Wrap(err, "print app")
}
Expand Down
5 changes: 3 additions & 2 deletions cli/cmd/app_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func (r *runners) InitAppList(parent *cobra.Command) *cobra.Command {
SilenceUsage: true,
}
parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

return cmd
}
Expand All @@ -29,7 +30,7 @@ func (r *runners) listApps(_ *cobra.Command, args []string) error {
}

if len(args) == 0 {
return print.Apps(r.w, kotsApps)
return print.Apps(r.outputFormat, r.w, kotsApps)
}

appSearch := args[0]
Expand All @@ -39,5 +40,5 @@ func (r *runners) listApps(_ *cobra.Command, args []string) error {
resultApps = append(resultApps, app)
}
}
return print.Apps(r.w, resultApps)
return print.Apps(r.outputFormat, r.w, resultApps)
}
3 changes: 2 additions & 1 deletion cli/cmd/channel_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (r *runners) InitChannelCreate(parent *cobra.Command) {

cmd.Flags().StringVar(&r.args.channelCreateName, "name", "", "The name of this channel")
cmd.Flags().StringVar(&r.args.channelCreateDescription, "description", "", "A longer description of this channel")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.channelCreate
}
Expand All @@ -29,5 +30,5 @@ func (r *runners) channelCreate(cmd *cobra.Command, args []string) error {
return err
}

return print.Channels(r.w, allChannels)
return print.Channels(r.outputFormat, r.w, allChannels)
}
4 changes: 2 additions & 2 deletions cli/cmd/channel_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (r *runners) InitChannelInspect(parent *cobra.Command) {
Long: "Show full details for a channel",
}
parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.args.channelInspectOutputFormat, "output", "text", "The output format to use. One of: json|text (default: text)")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.channelInspect
}
Expand All @@ -31,7 +31,7 @@ func (r *runners) channelInspect(_ *cobra.Command, args []string) error {
return err
}

if err = print.ChannelAttrs(r.args.channelInspectOutputFormat, r.w, r.appType, r.appSlug, appChan); err != nil {
if err = print.ChannelAttrs(r.outputFormat, r.w, r.appType, r.appSlug, appChan); err != nil {
return err
}

Expand Down
4 changes: 3 additions & 1 deletion cli/cmd/channel_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func (r *runners) InitChannelList(parent *cobra.Command) {
}

parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.channelList
}

Expand All @@ -22,5 +24,5 @@ func (r *runners) channelList(cmd *cobra.Command, args []string) error {
return err
}

return print.Channels(r.w, channels)
return print.Channels(r.outputFormat, r.w, channels)
}
6 changes: 3 additions & 3 deletions cli/cmd/customer_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (r *runners) InitCustomersCreateCommand(parent *cobra.Command) *cobra.Comma
Short: "create a customer",
Long: `create a customer`,
RunE: r.createCustomer,
SilenceUsage: true,
SilenceUsage: false,
SilenceErrors: true, // this command uses custom error printing
}
parent.AddCommand(cmd)
Expand All @@ -34,9 +34,9 @@ func (r *runners) InitCustomersCreateCommand(parent *cobra.Command) *cobra.Comma
return cmd
}

func (r *runners) createCustomer(_ *cobra.Command, _ []string) (err error) {
func (r *runners) createCustomer(cmd *cobra.Command, _ []string) (err error) {
defer func() {
printIfError(err)
printIfError(cmd, err)
}()

// all of the following validation occurs in the API also, but
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/customer_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (r *runners) InitCustomersInspectCommand(parent *cobra.Command) *cobra.Comm
}
parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.args.customerInspectCustomer, "customer", "", "The Customer Name or ID")
cmd.Flags().StringVar(&r.args.customerInspectOutputFormat, "output", "text", "The output format to use. One of: json|text (default: text)")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

return cmd
}
Expand All @@ -46,7 +46,7 @@ func (r *runners) inspectCustomer(_ *cobra.Command, _ []string) error {
return errors.Wrapf(err, "get registry hostname for customer %q", r.args.customerInspectCustomer)
}

if err = print.CustomerAttrs(r.args.customerInspectOutputFormat, r.w, r.appType, r.appSlug, ch, regHost, customer); err != nil {
if err = print.CustomerAttrs(r.outputFormat, r.w, r.appType, r.appSlug, ch, regHost, customer); err != nil {
return err
}

Expand Down
5 changes: 0 additions & 5 deletions cli/cmd/customer_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,5 @@ func (r *runners) listCustomers(_ *cobra.Command, _ []string) error {
return errors.Wrap(err, "list customers by app and app version")
}
return print.CustomersWithInstances(r.outputFormat, r.w, customers)
if err != nil {
return errors.Wrap(err, "list customers")
}
return errors.New("Failed to list customers")

}
}
3 changes: 2 additions & 1 deletion cli/cmd/enterprise_channel_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (r *runners) InitEnterpriseChannelCreate(parent *cobra.Command) {

cmd.Flags().StringVar(&r.args.enterpriseChannelCreateName, "name", "", "The name of this channel")
cmd.Flags().StringVar(&r.args.enterpriseChannelCreateDescription, "description", "", "A longer description of this channel")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.enterpriseChannelCreate
}
Expand All @@ -29,6 +30,6 @@ func (r *runners) enterpriseChannelCreate(cmd *cobra.Command, args []string) err
return err
}

print.EnterpriseChannel(r.w, channel)
print.EnterpriseChannel(r.outputFormat, r.w, channel)
return nil
}
3 changes: 2 additions & 1 deletion cli/cmd/enterprise_channel_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (r *runners) InitEnterpriseChannelLS(parent *cobra.Command) *cobra.Command
SilenceUsage: true,
}
parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

return cmd
}
Expand All @@ -24,6 +25,6 @@ func (r *runners) enterpriseChannelList(cmd *cobra.Command, args []string) error
return err
}

print.EnterpriseChannels(r.w, channels)
print.EnterpriseChannels(r.outputFormat, r.w, channels)
return nil
}
3 changes: 2 additions & 1 deletion cli/cmd/enterprise_channel_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (r *runners) InitEnterpriseChannelUpdate(parent *cobra.Command) {
cmd.Flags().StringVar(&r.args.enterpriseChannelUpdateID, "id", "", "The id of the channel to be updated")
cmd.Flags().StringVar(&r.args.enterpriseChannelUpdateName, "name", "", "The new name for this channel")
cmd.Flags().StringVar(&r.args.enterpriseChannelUpdateDescription, "description", "", "The new description of this channel")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.enterpriseChannelUpdate
}
Expand All @@ -30,6 +31,6 @@ func (r *runners) enterpriseChannelUpdate(cmd *cobra.Command, args []string) err
return err
}

print.EnterpriseChannel(r.w, channel)
print.EnterpriseChannel(r.outputFormat, r.w, channel)
return nil
}
3 changes: 2 additions & 1 deletion cli/cmd/enterprise_installer_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (r *runners) InitEnterpriseInstallerCreate(parent *cobra.Command) {
parent.AddCommand(cmd)

cmd.Flags().StringVar(&r.args.enterpriseInstallerCreateFile, "yaml-file", "", "The filename containing the installer yaml")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.enterpriseInstallerCreate
}
Expand All @@ -36,6 +37,6 @@ func (r *runners) enterpriseInstallerCreate(cmd *cobra.Command, args []string) e
return err
}

print.EnterpriseInstaller(r.w, installer)
print.EnterpriseInstaller(r.outputFormat, r.w, installer)
return nil
}
3 changes: 2 additions & 1 deletion cli/cmd/enterprise_installer_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (r *runners) InitEnterpriseInstallerLS(parent *cobra.Command) *cobra.Comman
SilenceUsage: true,
}
parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

return cmd
}
Expand All @@ -24,6 +25,6 @@ func (r *runners) enterpriseInstallerList(cmd *cobra.Command, args []string) err
return err
}

print.EnterpriseInstallers(r.w, installers)
print.EnterpriseInstallers(r.outputFormat, r.w, installers)
return nil
}
3 changes: 2 additions & 1 deletion cli/cmd/enterprise_installer_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (r *runners) InitEnterpriseInstallerUpdate(parent *cobra.Command) {

cmd.Flags().StringVar(&r.args.enterpriseInstallerUpdateID, "id", "", "The id of the installer to be updated")
cmd.Flags().StringVar(&r.args.enterpriseInstallerUpdateFile, "yaml-file", "", "The filename containing the installer yaml")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.enterpriseInstallerUpdate
}
Expand All @@ -37,6 +38,6 @@ func (r *runners) enterpriseInstallerUpdate(cmd *cobra.Command, args []string) e
return err
}

print.EnterpriseInstaller(r.w, installer)
print.EnterpriseInstaller(r.outputFormat, r.w, installer)
return nil
}
7 changes: 4 additions & 3 deletions cli/cmd/enterprise_policy_create.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"io/ioutil"
"os"

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
Expand All @@ -23,12 +23,13 @@ func (r *runners) InitEnterprisePolicyCreate(parent *cobra.Command) {
cmd.Flags().StringVar(&r.args.enterprisePolicyCreateName, "name", "", "The name of this policy")
cmd.Flags().StringVar(&r.args.enterprisePolicyCreateDescription, "description", "", "A longer description of this policy")
cmd.Flags().StringVar(&r.args.enterprisePolicyCreateFile, "policy-file", "", "The filename containing an OPA policy")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.enterprisePolicyCreate
}

func (r *runners) enterprisePolicyCreate(cmd *cobra.Command, args []string) error {
b, err := ioutil.ReadFile(r.args.enterprisePolicyCreateFile)
b, err := os.ReadFile(r.args.enterprisePolicyCreateFile)
if err != nil {
return errors.Wrap(err, "failed to read file")
}
Expand All @@ -38,6 +39,6 @@ func (r *runners) enterprisePolicyCreate(cmd *cobra.Command, args []string) erro
return err
}

print.EnterprisePolicy(r.w, policy)
print.EnterprisePolicy(r.outputFormat, r.w, policy)
return nil
}
3 changes: 2 additions & 1 deletion cli/cmd/enterprise_policy_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func (r *runners) InitEnterprisePolicyLS(parent *cobra.Command) *cobra.Command {
SilenceUsage: true,
}
parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

return cmd
}
Expand All @@ -32,6 +33,6 @@ func (r *runners) enterprisePolicyList(cmd *cobra.Command, args []string) error
return nil
}

print.EnterprisePolicies(r.w, policies)
print.EnterprisePolicies(r.outputFormat, r.w, policies)
return nil
}
7 changes: 4 additions & 3 deletions cli/cmd/enterprise_policy_update.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"io/ioutil"
"os"

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
Expand All @@ -24,12 +24,13 @@ func (r *runners) InitEnterprisePolicyUpdate(parent *cobra.Command) {
cmd.Flags().StringVar(&r.args.enterprisePolicyUpdateName, "name", "", "The new name for this policy")
cmd.Flags().StringVar(&r.args.enterprisePolicyUpdateDescription, "description", "", "The new description of this policy")
cmd.Flags().StringVar(&r.args.enterprisePolicyUpdateFile, "policy-file", "", "The filename containing an OPA policy")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.enterprisePolicyUpdate
}

func (r *runners) enterprisePolicyUpdate(cmd *cobra.Command, args []string) error {
b, err := ioutil.ReadFile(r.args.enterprisePolicyUpdateFile)
b, err := os.ReadFile(r.args.enterprisePolicyUpdateFile)
if err != nil {
return errors.Wrap(err, "failed to read file")
}
Expand All @@ -39,6 +40,6 @@ func (r *runners) enterprisePolicyUpdate(cmd *cobra.Command, args []string) erro
return err
}

print.EnterprisePolicy(r.w, policy)
print.EnterprisePolicy(r.outputFormat, r.w, policy)
return nil
}
4 changes: 3 additions & 1 deletion cli/cmd/installer_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func (r *runners) InitInstallerList(parent *cobra.Command) {
}

parent.AddCommand(cmd)
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.installerList
}

Expand All @@ -22,5 +24,5 @@ func (r *runners) installerList(_ *cobra.Command, _ []string) error {
return err
}

return print.Installers(r.w, installers)
return print.Installers(r.outputFormat, r.w, installers)
}
3 changes: 2 additions & 1 deletion cli/cmd/registry_add_dockerhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (r *runners) InitRegistryAddDockerHub(parent *cobra.Command) *cobra.Command
cmd.Flags().BoolVar(&r.args.addRegistryPasswordFromStdIn, "password-stdin", false, "Take the password from stdin")
cmd.Flags().StringVar(&r.args.addRegistryToken, "token", "", "The token to authenticate to the registry with")
cmd.Flags().BoolVar(&r.args.addRegistryTokenFromStdIn, "token-stdin", false, "Take the token from stdin")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.registryAddDockerHub

Expand Down Expand Up @@ -72,7 +73,7 @@ func (r *runners) registryAddDockerHub(cmd *cobra.Command, args []string) error
*registry,
}

return print.Registries(r.w, registries)
return print.Registries(r.outputFormat, r.w, registries)
}

func (r *runners) validateRegistryAddDockerHub() (kotsclient.AddKOTSRegistryRequest, []error) {
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/registry_add_ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (r *runners) InitRegistryAddECR(parent *cobra.Command) {
cmd.Flags().StringVar(&r.args.addRegistryAccessKeyID, "accesskeyid", "", "The access key id to authenticate to the registry with")
cmd.Flags().StringVar(&r.args.addRegistrySecretAccessKey, "secretaccesskey", "", "The secret access key to authenticate to the registry with")
cmd.Flags().BoolVar(&r.args.addRegistrySecretAccessKeyFromStdIn, "secretaccesskey-stdin", false, "Take the secret access key from stdin")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.registryAddECR
}
Expand Down Expand Up @@ -60,7 +61,7 @@ func (r *runners) registryAddECR(cmd *cobra.Command, args []string) error {
*registry,
}

return print.Registries(r.w, registries)
return print.Registries(r.outputFormat, r.w, registries)
}

func (r *runners) validateRegistryAddECR() (kotsclient.AddKOTSRegistryRequest, []error) {
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/registry_add_gcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (r *runners) InitRegistryAddGCR(parent *cobra.Command) {
cmd.Flags().StringVar(&r.args.addRegistryEndpoint, "endpoint", "", "The GCR endpoint")
cmd.Flags().StringVar(&r.args.addRegistryServiceAccountKey, "serviceaccountkey", "", "The service account key to authenticate to the registry with")
cmd.Flags().BoolVar(&r.args.addRegistryServiceAccountKeyFromStdIn, "serviceaccountkey-stdin", false, "Take the service account key from stdin")
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)")

cmd.RunE = r.registryAddGCR
}
Expand Down Expand Up @@ -59,7 +60,7 @@ func (r *runners) registryAddGCR(cmd *cobra.Command, args []string) error {
*registry,
}

return print.Registries(r.w, registries)
return print.Registries(r.outputFormat, r.w, registries)

}

Expand Down
Loading

0 comments on commit 8db43f8

Please sign in to comment.