diff --git a/cmd/root.go b/cmd/root.go index 083f80d..8deeac5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,7 +5,7 @@ Copyright © 2022 Seednode package cmd import ( - "fmt" + "log" "github.com/spf13/cobra" ) @@ -26,8 +26,7 @@ var rootCmd = &cobra.Command{ func Execute() { err := rootCmd.Execute() if err != nil { - fmt.Println(err) - panic(Exit{1}) + log.Fatal(err) } } diff --git a/cmd/web.go b/cmd/web.go index f068a52..2270853 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -16,6 +16,17 @@ import ( "strings" ) +type Exit struct{ Code int } + +func HandleExit() { + if e := recover(); e != nil { + if exit, ok := e.(Exit); ok == true { + os.Exit(exit.Code) + } + panic(e) + } +} + func generatePageHtml(w http.ResponseWriter, paths []string) error { fileList, err := getFileList(paths) if err != nil {