Skip to content

Commit e29b69b

Browse files
authored
Add tasklisttype flag to ListTaskListPartitions (#6711)
* add task list type flag to ListTaskListPartitions * change usage help comment
1 parent fafe9b6 commit e29b69b

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

tools/cli/task_list.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func newTaskListCommands() []*cli.Command {
5353
Aliases: []string{"tl"},
5454
Usage: "TaskList description",
5555
},
56+
&cli.StringFlag{
57+
Name: FlagTaskListType,
58+
Aliases: []string{"tlt"},
59+
Value: "decision",
60+
Usage: "Optional TaskList type [decision|activity]",
61+
},
5662
},
5763
Action: ListTaskListPartitions,
5864
},

tools/cli/task_list_commands.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ func ListTaskListPartitions(c *cli.Context) error {
9999
if err != nil {
100100
return commoncli.Problem("Required flag not found: ", err)
101101
}
102+
taskListType := strToTaskListType(c.String(FlagTaskListType)) // default type is decision
103+
102104
ctx, cancel, err := newContext(c)
103105
defer cancel()
104106
if err != nil {
@@ -113,13 +115,16 @@ func ListTaskListPartitions(c *cli.Context) error {
113115
if err != nil {
114116
return commoncli.Problem("Operation ListTaskListPartitions failed.", err)
115117
}
116-
if len(response.DecisionTaskListPartitions) > 0 {
117-
return printTaskListPartitions("Decision", response.DecisionTaskListPartitions)
118-
}
119-
if len(response.ActivityTaskListPartitions) > 0 {
120-
return printTaskListPartitions("Activity", response.ActivityTaskListPartitions)
118+
119+
switch taskListType {
120+
case types.TaskListTypeActivity:
121+
return printTaskListPartitions(types.TaskListTypeActivity, response.ActivityTaskListPartitions)
122+
case types.TaskListTypeDecision:
123+
return printTaskListPartitions(types.TaskListTypeDecision, response.DecisionTaskListPartitions)
124+
default:
125+
// should never happen
126+
return nil
121127
}
122-
return nil
123128
}
124129

125130
func printTaskListPollers(w io.Writer, pollers []*types.PollerInfo, taskListType types.TaskListType) error {
@@ -136,7 +141,7 @@ func printTaskListPollers(w io.Writer, pollers []*types.PollerInfo, taskListType
136141
}})
137142
}
138143

139-
func printTaskListPartitions(taskListType string, partitions []*types.TaskListPartitionMetadata) error {
144+
func printTaskListPartitions(taskListType types.TaskListType, partitions []*types.TaskListPartitionMetadata) error {
140145
table := []TaskListPartitionRow{}
141146
for _, partition := range partitions {
142147
table = append(table, TaskListPartitionRow{
@@ -146,7 +151,7 @@ func printTaskListPartitions(taskListType string, partitions []*types.TaskListPa
146151
})
147152
}
148153
return RenderTable(os.Stdout, table, RenderOptions{Color: true, OptionalColumns: map[string]bool{
149-
"Activity Task List Partition": taskListType == "Activity",
150-
"Decision Task List Partition": taskListType == "Decision",
154+
"Activity Task List Partition": taskListType == types.TaskListTypeActivity,
155+
"Decision Task List Partition": taskListType == types.TaskListTypeDecision,
151156
}})
152157
}

tools/cli/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ func parseTimeDuration(duration string) (dur time.Duration, err error) {
693693
return
694694
}
695695

696+
// strToTaskListType converts str to types.TaskListType
697+
// if it's not matched, it returns types.TaskListTypeDecision
696698
func strToTaskListType(str string) types.TaskListType {
697699
if strings.ToLower(str) == "activity" {
698700
return types.TaskListTypeActivity

0 commit comments

Comments
 (0)