Replace fmt.Println() + os.Exit(1) with log.Fatal() in error handler, error out if no useful paths are passed in
This commit is contained in:
parent
af9b79878f
commit
4679208eae
|
@ -649,7 +649,7 @@ func normalizePath(path string) (string, error) {
|
|||
}
|
||||
|
||||
func normalizePaths(args []string) ([]string, error) {
|
||||
paths := make([]string, len(args))
|
||||
var paths []string
|
||||
|
||||
var pathList strings.Builder
|
||||
pathList.WriteString("Paths:\n")
|
||||
|
@ -683,7 +683,7 @@ func normalizePaths(args []string) ([]string, error) {
|
|||
}
|
||||
|
||||
if addPath {
|
||||
paths[i] = path
|
||||
paths = append(paths, path)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@ Copyright © 2023 Seednode <seednode@seedno.de>
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -48,8 +47,7 @@ var (
|
|||
func Execute() {
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,5 +74,5 @@ func init() {
|
|||
})
|
||||
|
||||
rootCmd.SetVersionTemplate("roulette v{{.Version}}\n")
|
||||
rootCmd.Version = "0.48.0"
|
||||
rootCmd.Version = "0.49.0"
|
||||
}
|
||||
|
|
|
@ -943,8 +943,7 @@ func ServePage(args []string) error {
|
|||
|
||||
bindAddr := net.ParseIP(bindHost[0])
|
||||
if bindAddr == nil {
|
||||
fmt.Println("Invalid bind address provided. Please specify a hostname, or an IPv4 or IPv6 address in dotted decimal or IPv6 format.")
|
||||
os.Exit(1)
|
||||
return errors.New("invalid bind address provided")
|
||||
}
|
||||
|
||||
paths, err := normalizePaths(args)
|
||||
|
@ -953,8 +952,7 @@ func ServePage(args []string) error {
|
|||
}
|
||||
|
||||
if len(paths) == 0 {
|
||||
fmt.Println("No supported files found in provided paths. Exiting.")
|
||||
os.Exit(0)
|
||||
return errors.New("no supported files found in provided paths")
|
||||
}
|
||||
|
||||
Regexes := &Regexes{
|
||||
|
|
Loading…
Reference in New Issue