Skip to content

Commit

Permalink
CLI add print search attributes option (cadence-workflow#1967)
Browse files Browse the repository at this point in the history
  • Loading branch information
vancexu authored Jun 7, 2019
1 parent 81e91c1 commit ee5f5e8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gen/go/shared/idl.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions tools/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,10 @@ func createTableForListWorkflow(c *cli.Context, listAll bool, queryOpen bool) *t
header = append(header, "Memo")
headerColor = append(headerColor, tableHeaderBlue)
}
if printSearchAttr := c.Bool(FlagPrintSearchAttr); printSearchAttr {
header = append(header, "Search Attributes")
headerColor = append(headerColor, tableHeaderBlue)
}
table.SetHeader(header)
if !listAll { // color is only friendly to ANSI terminal
table.SetHeaderColor(headerColor...)
Expand All @@ -1128,6 +1132,7 @@ func listWorkflow(c *cli.Context, table *tablewriter.Table, queryOpen bool) func
printRawTime := c.Bool(FlagPrintRawTime)
printDateTime := c.Bool(FlagPrintDateTime)
printMemo := c.Bool(FlagPrintMemo)
printSearchAttr := c.Bool(FlagPrintSearchAttr)
pageSize := c.Int(FlagPageSize)
if pageSize <= 0 {
pageSize = defaultPageSizeForList
Expand Down Expand Up @@ -1177,6 +1182,9 @@ func listWorkflow(c *cli.Context, table *tablewriter.Table, queryOpen bool) func
if printMemo {
row = append(row, getPrintableMemo(e.Memo))
}
if printSearchAttr {
row = append(row, getPrintableSearchAttr(e.SearchAttributes))
}
table.Append(row)
}

Expand Down Expand Up @@ -2147,6 +2155,16 @@ func getPrintableMemo(memo *s.Memo) string {
return buf.String()
}

func getPrintableSearchAttr(searchAttr *s.SearchAttributes) string {
buf := new(bytes.Buffer)
for k, v := range searchAttr.IndexedFields {
var decodedVal interface{}
json.Unmarshal(v, &decodedVal)
fmt.Fprintf(buf, "%s=%v\n", k, decodedVal)
}
return buf.String()
}

func truncate(str string) string {
if len(str) > maxOutputStringLength {
return str[:maxOutputStringLength]
Expand Down
6 changes: 6 additions & 0 deletions tools/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ const (
FlagPrintDateTimeWithAlias = FlagPrintDateTime + ", pdt"
FlagPrintMemo = "print_memo"
FlagPrintMemoWithAlias = FlagPrintMemo + ", pme"
FlagPrintSearchAttr = "print_search_attr"
FlagPrintSearchAttrWithAlias = FlagPrintSearchAttr + ", psa"
FlagPrintJSON = "print_json"
FlagPrintJSONWithAlias = FlagPrintJSON + ", pjson"
FlagDescription = "description"
Expand Down Expand Up @@ -362,6 +364,10 @@ func getFlagsForListAll() []cli.Flag {
Name: FlagPrintMemoWithAlias,
Usage: "Print memo",
},
cli.BoolFlag{
Name: FlagPrintSearchAttrWithAlias,
Usage: "Print search attributes",
},
cli.BoolFlag{
Name: FlagPrintFullyDetailWithAlias,
Usage: "Print full message without table format",
Expand Down

0 comments on commit ee5f5e8

Please sign in to comment.