summaryrefslogtreecommitdiff
path: root/cmd/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/main.go')
-rw-r--r--cmd/main.go49
1 files changed, 4 insertions, 45 deletions
diff --git a/cmd/main.go b/cmd/main.go
index 09246f4..44e339a 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -33,6 +33,7 @@ import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/certmagic"
+ "github.com/spf13/pflag"
"go.uber.org/zap"
)
@@ -58,35 +59,9 @@ func Main() {
os.Args = append(os.Args, "help")
}
- subcommandName := os.Args[1]
- subcommand, ok := commands[subcommandName]
- if !ok {
- if strings.HasPrefix(os.Args[1], "-") {
- // user probably forgot to type the subcommand
- fmt.Println("[ERROR] first argument must be a subcommand; see 'caddy help'")
- } else {
- fmt.Printf("[ERROR] '%s' is not a recognized subcommand; see 'caddy help'\n", os.Args[1])
- }
- os.Exit(caddy.ExitCodeFailedStartup)
- }
-
- fs := subcommand.Flags
- if fs == nil {
- fs = flag.NewFlagSet(subcommand.Name, flag.ExitOnError)
- }
-
- err := fs.Parse(os.Args[2:])
- if err != nil {
- fmt.Println(err)
- os.Exit(caddy.ExitCodeFailedStartup)
+ if err := rootCmd.Execute(); err != nil {
+ os.Exit(1)
}
-
- exitCode, err := subcommand.Func(Flags{fs})
- if err != nil {
- fmt.Fprintf(os.Stderr, "%s: %v\n", subcommand.Name, err)
- }
-
- os.Exit(exitCode)
}
// handlePingbackConn reads from conn and ensures it matches
@@ -280,7 +255,7 @@ func watchConfigFile(filename, adapterName string) {
// Flags wraps a FlagSet so that typed values
// from flags can be easily retrieved.
type Flags struct {
- *flag.FlagSet
+ *pflag.FlagSet
}
// String returns the string representation of the
@@ -326,22 +301,6 @@ func (f Flags) Duration(name string) time.Duration {
return val
}
-// flagHelp returns the help text for fs.
-func flagHelp(fs *flag.FlagSet) string {
- if fs == nil {
- return ""
- }
-
- // temporarily redirect output
- out := fs.Output()
- defer fs.SetOutput(out)
-
- buf := new(bytes.Buffer)
- fs.SetOutput(buf)
- fs.PrintDefaults()
- return buf.String()
-}
-
func loadEnvFromFile(envFile string) error {
file, err := os.Open(envFile)
if err != nil {