Skip to content

Commit

Permalink
print current workspace in interactive mode (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitemongerer authored Dec 3, 2024
1 parent 238491c commit dd2a85c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 2 additions & 4 deletions cmd/deploycreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cmd/workspacecurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/workspaceset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion pkg/command/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package command

import "context"
import (
"context"

"github.com/spf13/cobra"
)

type CTXOutputKey struct{}
type CTXOutputValue struct {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit dd2a85c

Please sign in to comment.