Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only display template IDs #402

Merged
merged 1 commit into from
Dec 24, 2020
Merged
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
36 changes: 29 additions & 7 deletions cmd/tink-cli/cmd/template/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ var (
updatedAt = "Updated At"
)

var (
quiet bool
t table.Writer
)

// listCmd represents the list subcommand for template command
var listCmd = &cobra.Command{
Use: "list",
Expand All @@ -34,15 +39,19 @@ var listCmd = &cobra.Command{
return nil
},
Run: func(cmd *cobra.Command, args []string) {
t := table.NewWriter()
if quiet {
listTemplates()
return
}
t = table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{id, name, createdAt, updatedAt})
listTemplates(cmd, t)
listTemplates()
t.Render()
},
}

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

var tmp *template.WorkflowTemplate
for tmp, err = list.Recv(); err == nil && tmp.Name != ""; tmp, err = list.Recv() {
printOutput(t, tmp)
}

if err != nil && err != io.EOF {
log.Fatal(err)
}
}

func printOutput(t table.Writer, tmp *template.WorkflowTemplate) {
if quiet {
fmt.Println(tmp.Id)
} else {
cr := tmp.CreatedAt
up := tmp.UpdatedAt
t.AppendRows([]table.Row{
{tmp.Id, tmp.Name, time.Unix(cr.Seconds, 0), time.Unix(up.Seconds, 0)},
})
}
}

if err != nil && err != io.EOF {
log.Fatal(err)
}
func addListFlags() {
flags := listCmd.Flags()
flags.BoolVarP(&quiet, "quiet", "q", false, "only display template IDs")
}

func init() {
listCmd.DisableFlagsInUseLine = true
addListFlags()
SubCommands = append(SubCommands, listCmd)
}