diff --git a/cmd/deploycreate.go b/cmd/deploycreate.go index 060820a..0e2a2b1 100644 --- a/cmd/deploycreate.go +++ b/cmd/deploycreate.go @@ -72,10 +72,8 @@ func init() { } // if wait flag is used, default to non-interactive output - outputFormat := command.GetFormatFromContext(cmd.Context()) - if input.Wait && outputFormat.Interactive() { - output := command.TEXT - cmd.SetContext(command.SetFormatInContext(cmd.Context(), &output)) + if input.Wait { + command.DefaultFormatNonInteractive(cmd) } nonInteractive := nonInteractiveDeployCreate(cmd, input) diff --git a/cmd/workspacecurrent.go b/cmd/workspacecurrent.go index 5d40983..00f37f4 100644 --- a/cmd/workspacecurrent.go +++ b/cmd/workspacecurrent.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/renderinc/cli/pkg/client" + "github.com/renderinc/cli/pkg/command" "github.com/renderinc/cli/pkg/config" "github.com/renderinc/cli/pkg/owner" ) @@ -14,6 +15,8 @@ var workspaceCurrentCmd = &cobra.Command{ Use: "current", Short: "Show the currently selected workspace", RunE: func(cmd *cobra.Command, args []string) error { + command.DefaultFormatNonInteractive(cmd) + c, err := client.NewDefaultClient() if err != nil { return fmt.Errorf("failed to create client: %w", err) diff --git a/cmd/workspaceset.go b/cmd/workspaceset.go index b6d2a07..2443fae 100644 --- a/cmd/workspaceset.go +++ b/cmd/workspaceset.go @@ -55,8 +55,8 @@ func nonInteractiveSetWorkspace(cmd *cobra.Command, workspaceIDOrName string) er } type printableOwner struct { - *client.Owner `json:"inline"` - prefix string + *client.Owner + prefix string } func (p *printableOwner) String() string { diff --git a/pkg/command/context.go b/pkg/command/context.go index 36fc5d2..bae265c 100644 --- a/pkg/command/context.go +++ b/pkg/command/context.go @@ -1,6 +1,10 @@ package command -import "context" +import ( + "context" + + "github.com/spf13/cobra" +) type CTXOutputKey struct{} type CTXOutputValue struct { @@ -35,3 +39,12 @@ func GetConfirmFromContext(ctx context.Context) bool { func SetConfirmInContext(ctx context.Context, confirm bool) context.Context { return context.WithValue(ctx, CTXConfirmKey{}, &CTXConfirmValue{Confirm: confirm}) } + +func DefaultFormatNonInteractive(cmd *cobra.Command) { + format := GetFormatFromContext(cmd.Context()) + if format.Interactive() { + newFormat := TEXT + ctx := SetFormatInContext(cmd.Context(), &newFormat) + cmd.SetContext(ctx) + } +}