From aeb20f4debd7b16abd0478e5b139017dcf38ebf0 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Costa Beppler Date: Wed, 11 Mar 2020 08:17:50 -0300 Subject: [PATCH] Adds --name flag to list command. (#1046) --- cmd/cmd_list.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/cmd_list.go b/cmd/cmd_list.go index e2ae4f99..ee0ff5b1 100644 --- a/cmd/cmd_list.go +++ b/cmd/cmd_list.go @@ -22,12 +22,16 @@ func createList() cli.Command { Name: "accounts, a", Usage: "Display accounts.", }, + cli.BoolFlag{ + Name: "names, n", + Usage: "Display certificate common names only.", + }, }, } } func list(ctx *cli.Context) error { - if ctx.Bool("accounts") { + if ctx.Bool("accounts") && !ctx.Bool("names") { if err := listAccount(ctx); err != nil { return err } @@ -44,12 +48,19 @@ func listCertificates(ctx *cli.Context) error { return err } + names := ctx.Bool("names") + if len(matches) == 0 { - fmt.Println("No certificates found.") + if !names { + fmt.Println("No certificates found.") + } return nil } - fmt.Println("Found the following certs:") + if !names { + fmt.Println("Found the following certs:") + } + for _, filename := range matches { if strings.HasSuffix(filename, ".issuer.crt") { continue @@ -65,11 +76,15 @@ func listCertificates(ctx *cli.Context) error { return err } - fmt.Println(" Certificate Name:", pCert.Subject.CommonName) - fmt.Println(" Domains:", strings.Join(pCert.DNSNames, ", ")) - fmt.Println(" Expiry Date:", pCert.NotAfter) - fmt.Println(" Certificate Path:", filename) - fmt.Println() + if names { + fmt.Println(pCert.Subject.CommonName) + } else { + fmt.Println(" Certificate Name:", pCert.Subject.CommonName) + fmt.Println(" Domains:", strings.Join(pCert.DNSNames, ", ")) + fmt.Println(" Expiry Date:", pCert.NotAfter) + fmt.Println(" Certificate Path:", filename) + fmt.Println() + } } return nil