summaryrefslogtreecommitdiff
path: root/modules/caddypki/command.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddypki/command.go')
-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)
+ },
})
}