Skip to content

Commit dd2a85c

Browse files
authored
print current workspace in interactive mode (#160)
1 parent 238491c commit dd2a85c

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

cmd/deploycreate.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ func init() {
7272
}
7373

7474
// if wait flag is used, default to non-interactive output
75-
outputFormat := command.GetFormatFromContext(cmd.Context())
76-
if input.Wait && outputFormat.Interactive() {
77-
output := command.TEXT
78-
cmd.SetContext(command.SetFormatInContext(cmd.Context(), &output))
75+
if input.Wait {
76+
command.DefaultFormatNonInteractive(cmd)
7977
}
8078

8179
nonInteractive := nonInteractiveDeployCreate(cmd, input)

cmd/workspacecurrent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/spf13/cobra"
77

88
"github.com/renderinc/cli/pkg/client"
9+
"github.com/renderinc/cli/pkg/command"
910
"github.com/renderinc/cli/pkg/config"
1011
"github.com/renderinc/cli/pkg/owner"
1112
)
@@ -14,6 +15,8 @@ var workspaceCurrentCmd = &cobra.Command{
1415
Use: "current",
1516
Short: "Show the currently selected workspace",
1617
RunE: func(cmd *cobra.Command, args []string) error {
18+
command.DefaultFormatNonInteractive(cmd)
19+
1720
c, err := client.NewDefaultClient()
1821
if err != nil {
1922
return fmt.Errorf("failed to create client: %w", err)

cmd/workspaceset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ func nonInteractiveSetWorkspace(cmd *cobra.Command, workspaceIDOrName string) er
5555
}
5656

5757
type printableOwner struct {
58-
*client.Owner `json:"inline"`
59-
prefix string
58+
*client.Owner
59+
prefix string
6060
}
6161

6262
func (p *printableOwner) String() string {

pkg/command/context.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package command
22

3-
import "context"
3+
import (
4+
"context"
5+
6+
"github.com/spf13/cobra"
7+
)
48

59
type CTXOutputKey struct{}
610
type CTXOutputValue struct {
@@ -35,3 +39,12 @@ func GetConfirmFromContext(ctx context.Context) bool {
3539
func SetConfirmInContext(ctx context.Context, confirm bool) context.Context {
3640
return context.WithValue(ctx, CTXConfirmKey{}, &CTXConfirmValue{Confirm: confirm})
3741
}
42+
43+
func DefaultFormatNonInteractive(cmd *cobra.Command) {
44+
format := GetFormatFromContext(cmd.Context())
45+
if format.Interactive() {
46+
newFormat := TEXT
47+
ctx := SetFormatInContext(cmd.Context(), &newFormat)
48+
cmd.SetContext(ctx)
49+
}
50+
}

0 commit comments

Comments
 (0)