2022-09-08 15:12:06 +00:00
|
|
|
/*
|
2023-01-18 17:19:29 +00:00
|
|
|
Copyright © 2023 Seednode <seednode@seedno.de>
|
2022-09-08 15:12:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-01-27 19:20:07 +00:00
|
|
|
"fmt"
|
2022-09-10 21:35:05 +00:00
|
|
|
"os"
|
2022-09-08 15:12:06 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-01-27 19:17:13 +00:00
|
|
|
var (
|
2023-02-05 20:34:22 +00:00
|
|
|
cache bool
|
|
|
|
cacheFile string
|
|
|
|
filtering bool
|
|
|
|
port uint16
|
|
|
|
recursive bool
|
|
|
|
sorting bool
|
|
|
|
statistics bool
|
|
|
|
verbose bool
|
2022-09-08 15:12:06 +00:00
|
|
|
|
2023-01-27 19:17:13 +00:00
|
|
|
rootCmd = &cobra.Command{
|
|
|
|
Use: "roulette <path> [path]...",
|
|
|
|
Short: "Serves random images from the specified directories.",
|
|
|
|
Args: cobra.MinimumNArgs(1),
|
2023-01-27 19:20:07 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2023-01-27 19:17:13 +00:00
|
|
|
err := ServePage(args)
|
|
|
|
if err != nil {
|
2023-01-27 19:20:07 +00:00
|
|
|
return err
|
2023-01-27 19:17:13 +00:00
|
|
|
}
|
2023-01-27 19:20:07 +00:00
|
|
|
|
|
|
|
return nil
|
2023-01-27 19:17:13 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
2022-09-08 15:12:06 +00:00
|
|
|
|
|
|
|
func Execute() {
|
|
|
|
err := rootCmd.Execute()
|
|
|
|
if err != nil {
|
2023-01-27 19:20:07 +00:00
|
|
|
fmt.Println(err)
|
2022-09-10 21:35:05 +00:00
|
|
|
os.Exit(1)
|
2022-09-08 15:12:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2023-01-27 19:17:13 +00:00
|
|
|
rootCmd.Flags().BoolVarP(&cache, "cache", "c", false, "generate directory cache at startup")
|
2023-02-05 20:34:22 +00:00
|
|
|
rootCmd.Flags().StringVar(&cacheFile, "cache-file", "", "path to optional persistent cache file")
|
2023-01-27 19:17:13 +00:00
|
|
|
rootCmd.Flags().BoolVarP(&filtering, "filter", "f", false, "enable filtering")
|
|
|
|
rootCmd.Flags().Uint16VarP(&port, "port", "p", 8080, "port to listen on")
|
|
|
|
rootCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "recurse into subdirectories")
|
|
|
|
rootCmd.Flags().BoolVarP(&sorting, "sort", "s", false, "enable sorting")
|
2023-02-05 20:34:22 +00:00
|
|
|
rootCmd.Flags().BoolVar(&statistics, "stats", false, "expose stats endpoint")
|
2023-01-27 19:17:13 +00:00
|
|
|
rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "log accessed files to stdout")
|
2022-09-10 21:17:55 +00:00
|
|
|
rootCmd.Flags().SetInterspersed(true)
|
2022-09-08 15:12:06 +00:00
|
|
|
}
|