Skip to content

Commit cd54c41

Browse files
committed
only display template IDs
Signed-off-by: Gaurav Gahlot <gauravgahlot0107@gmail.com>
1 parent a04ccb4 commit cd54c41

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

cmd/tink-cli/cmd/template/list.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ var (
2222
updatedAt = "Updated At"
2323
)
2424

25+
var (
26+
quiet bool
27+
t table.Writer
28+
)
29+
2530
// listCmd represents the list subcommand for template command
2631
var listCmd = &cobra.Command{
2732
Use: "list",
@@ -34,15 +39,19 @@ var listCmd = &cobra.Command{
3439
return nil
3540
},
3641
Run: func(cmd *cobra.Command, args []string) {
37-
t := table.NewWriter()
42+
if quiet {
43+
listTemplates()
44+
return
45+
}
46+
t = table.NewWriter()
3847
t.SetOutputMirror(os.Stdout)
3948
t.AppendHeader(table.Row{id, name, createdAt, updatedAt})
40-
listTemplates(cmd, t)
49+
listTemplates()
4150
t.Render()
4251
},
4352
}
4453

45-
func listTemplates(cmd *cobra.Command, t table.Writer) {
54+
func listTemplates() {
4655
list, err := client.TemplateClient.ListTemplates(context.Background(), &template.ListRequest{
4756
FilterBy: &template.ListRequest_Name{
4857
Name: "*",
@@ -54,19 +63,32 @@ func listTemplates(cmd *cobra.Command, t table.Writer) {
5463

5564
var tmp *template.WorkflowTemplate
5665
for tmp, err = list.Recv(); err == nil && tmp.Name != ""; tmp, err = list.Recv() {
66+
printOutput(t, tmp)
67+
}
68+
69+
if err != nil && err != io.EOF {
70+
log.Fatal(err)
71+
}
72+
}
73+
74+
func printOutput(t table.Writer, tmp *template.WorkflowTemplate) {
75+
if quiet {
76+
fmt.Println(tmp.Id)
77+
} else {
5778
cr := tmp.CreatedAt
5879
up := tmp.UpdatedAt
5980
t.AppendRows([]table.Row{
6081
{tmp.Id, tmp.Name, time.Unix(cr.Seconds, 0), time.Unix(up.Seconds, 0)},
6182
})
6283
}
84+
}
6385

64-
if err != nil && err != io.EOF {
65-
log.Fatal(err)
66-
}
86+
func addListFlags() {
87+
flags := listCmd.Flags()
88+
flags.BoolVarP(&quiet, "quiet", "q", false, "only display template IDs")
6789
}
6890

6991
func init() {
70-
listCmd.DisableFlagsInUseLine = true
92+
addListFlags()
7193
SubCommands = append(SubCommands, listCmd)
7294
}

0 commit comments

Comments
 (0)