Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions temporalcloudcli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/temporalio/cloud-cli/temporalcloudcli/internal/printer"
"go.temporal.io/api/common/v1"
"go.temporal.io/api/failure/v1"
"go.temporal.io/api/temporalproto"
"go.temporal.io/cloud-sdk/api/operation/v1"
"go.temporal.io/cloud-sdk/api/resource/v1"
"go.temporal.io/cloud-sdk/cloudclient"
"go.temporal.io/sdk/contrib/envconfig"
"golang.org/x/term"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"

"github.com/temporalio/cloud-cli/temporalcloudcli/internal/printer"
)

// Version is the value put as the default command version. This is often
Expand Down Expand Up @@ -458,13 +461,19 @@ var buildInfo string
func VersionString() string {
// To add build-time information to the version string, use
// go build -ldflags "-X github.com/temporalio/cloud-cli/temporalcloudcli.buildInfo=<MyString>"
var bi = buildInfo
bi := buildInfo
if bi != "" {
bi = fmt.Sprintf(", %s", bi)
}
return fmt.Sprintf("%s%s", Version, bi)
}

func registerKnownPrinterEnumToStringConverters(p *printer.Printer) {
// Register any enum converters for known types here.
printer.RegisterEnumToStringConverter[resource.ResourceState](p, "RESOURCE_STATE_", resource.ResourceState_name)
printer.RegisterEnumToStringConverter[operation.AsyncOperation_State](p, "STATE_", operation.AsyncOperation_State_name)
}

func (c *CloudCommand) preRun(cctx *CommandContext, timeoutCancel *context.CancelFunc) error {
// Set this command as the root
cctx.RootCommand = c
Expand Down Expand Up @@ -531,6 +540,7 @@ func (c *CloudCommand) preRun(cctx *CommandContext, timeoutCancel *context.Cance
default:
return fmt.Errorf("invalid time format %q", c.TimeFormat.Value)
}
registerKnownPrinterEnumToStringConverters(cctx.Printer)
}
cctx.JSONShorthandPayloads = !c.NoJsonShorthandPayloads
if c.CommandTimeout.Duration() > 0 {
Expand Down
10 changes: 7 additions & 3 deletions temporalcloudcli/commands.namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *CloudNamespaceGetCommand) run(cctx *CommandContext, _ []string) error {
if c.Spec {
return cctx.Printer.PrintStructured(n.Spec, printer.StructuredOptions{})
}
return cctx.Printer.PrintStructured(n, printer.StructuredOptions{})
return cctx.Printer.PrintResource(n, printer.PrintResourceOptions{})
}

func (c *CloudNamespaceEditCommand) run(cctx *CommandContext, _ []string) error {
Expand Down Expand Up @@ -271,14 +271,18 @@ func (c *CloudNamespaceListCommand) run(cctx *CommandContext, _ []string) error
return err
}

return cctx.Printer.PrintStructured(
return cctx.Printer.PrintResourceList(
struct {
Namespaces []*namespace.Namespace
NextPageToken string
}{
Namespaces: namespaces,
NextPageToken: nextPageToken,
},
printer.StructuredOptions{},
printer.PrintResourceOptions{
Fields: []string{"Namespace", "State", "CreatedTime"},
SpecFields: []string{"Regions"},
},
printer.TableOptions{},
)
}
2 changes: 1 addition & 1 deletion temporalcloudcli/commands.namespace.lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *CloudNamespaceLifecycleGetCommand) run(cctx *CommandContext, _ []string
EnableDeleteProtection: enableDeleteProtection,
}

return cctx.Printer.PrintStructured(result, printer.StructuredOptions{})
return cctx.Printer.PrintResource(result, printer.PrintResourceOptions{})
}

func (c *CloudNamespaceLifecycleSetCommand) run(cctx *CommandContext, _ []string) error {
Expand Down
Loading
Loading