From 7184542cb6c9513d74f0148d15a63afec1d469c3 Mon Sep 17 00:00:00 2001 From: Seednode Date: Thu, 11 May 2023 23:22:31 -0500 Subject: [PATCH] Updated transitive dependencies --- README.md | 9 +-------- cmd/files.go | 19 +++++++++++-------- cmd/root.go | 12 ++++++++++++ cmd/version.go | 26 -------------------------- cmd/web.go | 2 -- 5 files changed, 24 insertions(+), 44 deletions(-) delete mode 100644 cmd/version.go diff --git a/README.md b/README.md index 279b37d..19c101b 100644 --- a/README.md +++ b/README.md @@ -91,12 +91,6 @@ When accessed, these endpoints return the contents of the index, in HTML and JSO ``` Usage: roulette [path]... [flags] - roulette [command] - -Available Commands: - completion Generate the autocompletion script for the specified shell - help Help about any command - version Print version Flags: -b, --bind string address to bind to (default "0.0.0.0") @@ -111,6 +105,5 @@ Flags: --stats expose stats endpoint --stats-file string path to optional persistent stats file -v, --verbose log accessed files to stdout - -Use "roulette [command] --help" for more information about a command. + -V, --version display version and exit ``` \ No newline at end of file diff --git a/cmd/files.go b/cmd/files.go index 8a18c6e..dec51a4 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -649,9 +649,10 @@ func normalizePath(path string) (string, error) { } func normalizePaths(args []string) ([]string, error) { - paths := []string{} + paths := make([]string, len(args)) - fmt.Println("Paths:") + var pathList strings.Builder + pathList.WriteString("Paths:\n") for i := 0; i < len(args); i++ { path, err := normalizePath(args[i]) @@ -670,23 +671,25 @@ func normalizePaths(args []string) ([]string, error) { switch { case pathMatches && hasSupportedFiles: - fmt.Printf("%s\n", args[i]) + pathList.WriteString(fmt.Sprintf("%s\n", args[i])) addPath = true case !pathMatches && hasSupportedFiles: - fmt.Printf("%s (resolved to %s)\n", args[i], path) + pathList.WriteString(fmt.Sprintf("%s (resolved to %s)\n", args[i], path)) addPath = true case pathMatches && !hasSupportedFiles: - fmt.Printf("%s [No supported files found]\n", args[i]) + pathList.WriteString(fmt.Sprintf("%s [No supported files found]\n", args[i])) case !pathMatches && !hasSupportedFiles: - fmt.Printf("%s (resolved to %s) [No supported files found]\n", args[i], path) + pathList.WriteString(fmt.Sprintf("%s (resolved to %s) [No supported files found]\n", args[i], path)) } if addPath { - paths = append(paths, path) + paths[i] = path } } - fmt.Println() + if len(paths) > 0 { + fmt.Println(pathList.String()) + } return paths, nil } diff --git a/cmd/root.go b/cmd/root.go index 340e569..b352b97 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,6 +23,7 @@ var ( statistics bool statisticsFile string verbose bool + version bool rootCmd = &cobra.Command{ Use: "roulette [path]...", @@ -64,5 +65,16 @@ func init() { rootCmd.Flags().BoolVar(&statistics, "stats", false, "expose stats endpoint") rootCmd.Flags().StringVar(&statisticsFile, "stats-file", "", "path to optional persistent stats file") rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "log accessed files to stdout") + rootCmd.Flags().BoolVarP(&version, "version", "V", false, "display version and exit") rootCmd.Flags().SetInterspersed(true) + + rootCmd.CompletionOptions.HiddenDefaultCmd = true + + rootCmd.SilenceErrors = true + rootCmd.SetHelpCommand(&cobra.Command{ + Hidden: true, + }) + + rootCmd.SetVersionTemplate("roulette v{{.Version}}\n") + rootCmd.Version = "0.46.0" } diff --git a/cmd/version.go b/cmd/version.go deleted file mode 100644 index d104a03..0000000 --- a/cmd/version.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright © 2023 Seednode -*/ - -package cmd - -import ( - "fmt" - - "github.com/spf13/cobra" -) - -var Version = "0.45.1" - -func init() { - rootCmd.AddCommand(versionCmd) -} - -var versionCmd = &cobra.Command{ - Use: "version", - Short: "Print version", - Long: "Print the version number of roulette", - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("roulette v" + Version) - }, -} diff --git a/cmd/web.go b/cmd/web.go index a7a48ca..665b50f 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -838,8 +838,6 @@ func serveMedia(paths []string, Regexes *Regexes, index *Index) http.HandlerFunc func doNothing(http.ResponseWriter, *http.Request) {} func ServePage(args []string) error { - fmt.Printf("roulette v%s\n\n", Version) - bindHost, err := net.LookupHost(bind) if err != nil { return err