From 9c419f1e1a4a82a8ed49bac3d54050890cb3e58e Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Wed, 11 Oct 2023 11:46:18 -0400 Subject: cmd: Fix exiting with custom status code, add `caddy -v` (#5874) * Simplify variables for commands * Add --envfile support for adapt command * Carry custom status code for commands to os.Exit() * cmd: add `-v` and `--version` to root caddy command * Add `--envfile` to `caddy environ`, extract flag parsing to func --------- Co-authored-by: Mohammed Al Sahaf --- cmd/main.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'cmd/main.go') diff --git a/cmd/main.go b/cmd/main.go index b4e3fdc..fa15c08 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -17,6 +17,7 @@ package caddycmd import ( "bufio" "bytes" + "errors" "flag" "fmt" "io" @@ -63,6 +64,10 @@ func Main() { } if err := rootCmd.Execute(); err != nil { + var exitError *exitError + if errors.As(err, &exitError) { + os.Exit(exitError.ExitCode) + } os.Exit(1) } } -- cgit v1.2.3