Skip to content

Commit

Permalink
Split flags by categories in --help
Browse files Browse the repository at this point in the history
  • Loading branch information
feedmeapples committed Nov 18, 2022
1 parent defd085 commit 090aa4a
Show file tree
Hide file tree
Showing 15 changed files with 604 additions and 414 deletions.
11 changes: 11 additions & 0 deletions activity/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,32 @@ func NewActivityCommands() []*cli.Command {
Aliases: common.FlagWorkflowIDAlias,
Usage: "Workflow Id",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagRunID,
Aliases: common.FlagRunIDAlias,
Usage: "Run Id",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagActivityID,
Usage: "The Activity Id to complete",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagResult,
Usage: "Set the result value of completion",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagIdentity,
Usage: "Specify operator's identity",
Required: true,
Category: common.CategoryMain,
},
},
Action: func(c *cli.Context) error {
Expand All @@ -76,32 +81,38 @@ func NewActivityCommands() []*cli.Command {
Aliases: common.FlagWorkflowIDAlias,
Usage: "Workflow Id",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagRunID,
Aliases: common.FlagRunIDAlias,
Usage: "Run Id",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagActivityID,
Usage: "The Activity Id to fail",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagReason,
Usage: "Reason to fail the Activity",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagDetail,
Usage: "Detail to fail the Activity",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagIdentity,
Usage: "Specify operator's identity",
Required: true,
Category: common.CategoryMain,
},
},
Action: func(c *cli.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func commands(defaultCfg *sconfig.Config) []*cli.Command {
return append([]*cli.Command{
{
Name: "server",
Usage: "Commands for managing a Temporal server",
Usage: "Commands for managing Temporal server",
Subcommands: server.NewServerCommands(defaultCfg),
}}, common.WithFlags(clientCommands, common.SharedFlags)...)
}
Expand Down
31 changes: 31 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,37 @@ func (s *cliAppSuite) TestDescribeTaskQueue_Activity() {
s.sdkClient.AssertExpectations(s.T())
}

// TestFlagCategory_IsSet verifies that command flags have Category set
// As urfave/cli only prints flags in --help with Category set
func (s *cliAppSuite) TestFlagCategory_IsSet() {
for _, cmd := range s.app.Commands {
verifyCategory(s, cmd)
}
}

func verifyCategory(s *cliAppSuite, cmd *cli.Command) {
msgT := "flag %s should have a category, command: %s %s"

for _, flag := range cmd.Flags {
msg := fmt.Sprintf(msgT, "--"+flag.Names()[0], cmd.Name, cmd.Usage)

switch f := flag.(type) {
case *cli.BoolFlag:
s.NotEmpty(f.Category, msg)
case *cli.IntSliceFlag:
s.NotEmpty(f.Category, msg)
case *cli.StringFlag:
s.NotEmpty(f.Category, msg)
case *cli.StringSliceFlag:
s.NotEmpty(f.Category, msg)
}
}

for _, subCmd := range cmd.Subcommands {
verifyCategory(s, subCmd)
}
}

func historyEventIterator() sdkclient.HistoryEventIterator {
iteratorMock := &sdkmocks.HistoryEventIterator{}

Expand Down
8 changes: 5 additions & 3 deletions batch/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package batch

import (
"github.com/temporalio/tctl-kit/pkg/flags"
"github.com/temporalio/temporal-cli/common"
"github.com/urfave/cli/v2"
)
Expand All @@ -40,16 +39,17 @@ func NewBatchCommands() []*cli.Command {
Name: common.FlagJobID,
Usage: "Batch Job Id",
Required: true,
Category: common.CategoryMain,
},
}, flags.FlagsForRendering...),
}, common.FlagsForFormatting...),
Action: func(c *cli.Context) error {
return DescribeBatchJob(c)
},
},
{
Name: "list",
Usage: "List batch operation jobs",
Flags: flags.FlagsForPaginationAndRendering,
Flags: common.FlagsForPaginationAndRendering,
ArgsUsage: " ",
Action: func(c *cli.Context) error {
return ListBatchJobs(c)
Expand All @@ -63,11 +63,13 @@ func NewBatchCommands() []*cli.Command {
Name: common.FlagJobID,
Usage: "Batch Job Id",
Required: true,
Category: common.CategoryMain,
},
&cli.StringFlag{
Name: common.FlagReason,
Usage: "Reason to stop the batch job",
Required: true,
Category: common.CategoryMain,
},
},
Action: func(c *cli.Context) error {
Expand Down
42 changes: 24 additions & 18 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package cluster

import (
"github.com/temporalio/tctl-kit/pkg/flags"
"github.com/temporalio/tctl-kit/pkg/output"
"github.com/temporalio/temporal-cli/common"
"github.com/urfave/cli/v2"
Expand All @@ -46,14 +45,16 @@ func NewClusterCommands() []*cli.Command {
ArgsUsage: " ",
Flags: []cli.Flag{
&cli.StringFlag{
Name: output.FlagOutput,
Aliases: common.FlagOutputAlias,
Usage: output.UsageText,
Value: string(output.Table),
Name: output.FlagOutput,
Aliases: common.FlagOutputAlias,
Usage: output.UsageText,
Value: string(output.Table),
Category: common.CategoryFormatting,
},
&cli.StringFlag{
Name: output.FlagFields,
Usage: "customize fields to print. Set to 'long' to automatically print more of main fields",
Name: output.FlagFields,
Usage: "customize fields to print. Set to 'long' to automatically print more of main fields",
Category: common.CategoryFormatting,
},
},
Action: func(c *cli.Context) error {
Expand All @@ -66,14 +67,16 @@ func NewClusterCommands() []*cli.Command {
ArgsUsage: " ",
Flags: []cli.Flag{
&cli.StringFlag{
Name: output.FlagOutput,
Aliases: common.FlagOutputAlias,
Usage: output.UsageText,
Value: string(output.Table),
Name: output.FlagOutput,
Aliases: common.FlagOutputAlias,
Usage: output.UsageText,
Value: string(output.Table),
Category: common.CategoryFormatting,
},
&cli.StringFlag{
Name: output.FlagFields,
Usage: "customize fields to print. Set to 'long' to automatically print more of main fields",
Name: output.FlagFields,
Usage: "customize fields to print. Set to 'long' to automatically print more of main fields",
Category: common.CategoryFormatting,
},
},
Action: func(c *cli.Context) error {
Expand All @@ -86,12 +89,14 @@ func NewClusterCommands() []*cli.Command {
ArgsUsage: " ",
Flags: []cli.Flag{
&cli.StringFlag{
Name: common.FlagClusterAddress,
Usage: "Frontend address of the remote cluster",
Name: common.FlagClusterAddress,
Usage: "Frontend address of the remote cluster",
Category: common.CategoryMain,
},
&cli.BoolFlag{
Name: common.FlagClusterEnableConnection,
Usage: "Enable cross cluster connection",
Name: common.FlagClusterEnableConnection,
Usage: "Enable cross cluster connection",
Category: common.CategoryMain,
},
},
Action: func(c *cli.Context) error {
Expand All @@ -102,7 +107,7 @@ func NewClusterCommands() []*cli.Command {
Name: "list",
Usage: "List all remote clusters",
ArgsUsage: " ",
Flags: flags.FlagsForPaginationAndRendering,
Flags: common.FlagsForPaginationAndRendering,
Action: func(c *cli.Context) error {
return ListClusters(c)
},
Expand All @@ -116,6 +121,7 @@ func NewClusterCommands() []*cli.Command {
Name: common.FlagName,
Usage: "Frontend address of the remote cluster",
Required: true,
Category: common.CategoryMain,
},
},
Action: func(c *cli.Context) error {
Expand Down
Loading

0 comments on commit 090aa4a

Please sign in to comment.