summaryrefslogtreecommitdiff
path: root/modules/caddypki
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2023-02-24 18:09:12 -0500
committerGitHub <noreply@github.com>2023-02-24 16:09:12 -0700
commit9e6919550be5689628d0020ec14e90ea6f527716 (patch)
tree81865f63e5ef549f8548cd6e22e9aa89d4eaf207 /modules/caddypki
parent167981d258f41b7ef931d510056a5a5fdc9cbd0d (diff)
cmd: Expand cobra support, add short flags (#5379)
* cmd: Expand cobra support * Convert commands to cobra, add short flags * Fix version command typo Co-authored-by: Emily Lange <git@indeednotjames.com> * Apply suggestions from code review Co-authored-by: Matt Holt <mholt@users.noreply.github.com> --------- Co-authored-by: Emily Lange <git@indeednotjames.com> Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Diffstat (limited to 'modules/caddypki')
-rw-r--r--modules/caddypki/command.go36
1 files changed, 16 insertions, 20 deletions
diff --git a/modules/caddypki/command.go b/modules/caddypki/command.go
index cb86c93..e78f35c 100644
--- a/modules/caddypki/command.go
+++ b/modules/caddypki/command.go
@@ -18,7 +18,6 @@ import (
"crypto/x509"
"encoding/json"
"encoding/pem"
- "flag"
"fmt"
"net/http"
"os"
@@ -27,12 +26,12 @@ import (
"github.com/caddyserver/caddy/v2"
caddycmd "github.com/caddyserver/caddy/v2/cmd"
"github.com/smallstep/truststore"
+ "github.com/spf13/cobra"
)
func init() {
caddycmd.RegisterCommand(caddycmd.Command{
Name: "trust",
- Func: cmdTrust,
Usage: "[--ca <id>] [--address <listen>] [--config <path> [--adapter <name>]]",
Short: "Installs a CA certificate into local trust stores",
Long: `
@@ -53,19 +52,17 @@ This command will attempt to connect to Caddy's admin API running at
'` + caddy.DefaultAdminListen + `' to fetch the root certificate. You may
explicitly specify the --address, or use the --config flag to load
the admin address from your config, if not using the default.`,
- Flags: func() *flag.FlagSet {
- fs := flag.NewFlagSet("trust", flag.ExitOnError)
- fs.String("ca", "", "The ID of the CA to trust (defaults to 'local')")
- fs.String("address", "", "Address of the administration API listener (if --config is not used)")
- fs.String("config", "", "Configuration file (if --address is not used)")
- fs.String("adapter", "", "Name of config adapter to apply (if --config is used)")
- return fs
- }(),
+ CobraFunc: func(cmd *cobra.Command) {
+ cmd.Flags().StringP("ca", "", "", "The ID of the CA to trust (defaults to 'local')")
+ cmd.Flags().StringP("address", "", "", "Address of the administration API listener (if --config is not used)")
+ cmd.Flags().StringP("config", "c", "", "Configuration file (if --address is not used)")
+ cmd.Flags().StringP("adapter", "a", "", "Name of config adapter to apply (if --config is used)")
+ cmd.RunE = caddycmd.WrapCommandFuncForCobra(cmdTrust)
+ },
})
caddycmd.RegisterCommand(caddycmd.Command{
Name: "untrust",
- Func: cmdUntrust,
Usage: "[--cert <path>] | [[--ca <id>] [--address <listen>] [--config <path> [--adapter <name>]]]",
Short: "Untrusts a locally-trusted CA certificate",
Long: `
@@ -89,15 +86,14 @@ will attempt to connect to the Caddy's admin API running at
'` + caddy.DefaultAdminListen + `' to fetch the root certificate.
You may explicitly specify the --address, or use the --config flag
to load the admin address from your config, if not using the default.`,
- Flags: func() *flag.FlagSet {
- fs := flag.NewFlagSet("untrust", flag.ExitOnError)
- fs.String("cert", "", "The path to the CA certificate to untrust")
- fs.String("ca", "", "The ID of the CA to untrust (defaults to 'local')")
- fs.String("address", "", "Address of the administration API listener (if --config is not used)")
- fs.String("config", "", "Configuration file (if --address is not used)")
- fs.String("adapter", "", "Name of config adapter to apply (if --config is used)")
- return fs
- }(),
+ CobraFunc: func(cmd *cobra.Command) {
+ cmd.Flags().StringP("cert", "p", "", "The path to the CA certificate to untrust")
+ cmd.Flags().StringP("ca", "", "", "The ID of the CA to untrust (defaults to 'local')")
+ cmd.Flags().StringP("address", "", "", "Address of the administration API listener (if --config is not used)")
+ cmd.Flags().StringP("config", "c", "", "Configuration file (if --address is not used)")
+ cmd.Flags().StringP("adapter", "a", "", "Name of config adapter to apply (if --config is used)")
+ cmd.RunE = caddycmd.WrapCommandFuncForCobra(cmdUntrust)
+ },
})
}