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) {
|
func normalizePaths(args []string) ([]string, error) {
|
||||||
paths := make([]string, len(args))
|
var paths []string
|
||||||
|
|
||||||
var pathList strings.Builder
|
var pathList strings.Builder
|
||||||
pathList.WriteString("Paths:\n")
|
pathList.WriteString("Paths:\n")
|
||||||
|
@ -683,7 +683,7 @@ func normalizePaths(args []string) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if addPath {
|
if addPath {
|
||||||
paths[i] = path
|
paths = append(paths, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@ Copyright © 2023 Seednode <seednode@seedno.de>
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -48,8 +47,7 @@ var (
|
||||||
func Execute() {
|
func Execute() {
|
||||||
err := rootCmd.Execute()
|
err := rootCmd.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Fatal(err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,5 +74,5 @@ func init() {
|
||||||
})
|
})
|
||||||
|
|
||||||
rootCmd.SetVersionTemplate("roulette v{{.Version}}\n")
|
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])
|
bindAddr := net.ParseIP(bindHost[0])
|
||||||
if bindAddr == nil {
|
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.")
|
return errors.New("invalid bind address provided")
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
paths, err := normalizePaths(args)
|
paths, err := normalizePaths(args)
|
||||||
|
@ -953,8 +952,7 @@ func ServePage(args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(paths) == 0 {
|
if len(paths) == 0 {
|
||||||
fmt.Println("No supported files found in provided paths. Exiting.")
|
return errors.New("no supported files found in provided paths")
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Regexes := &Regexes{
|
Regexes := &Regexes{
|
||||||
|
|
Loading…
Reference in New Issue