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-05-31 18:01:24 +00:00
|
|
|
"log"
|
2022-09-08 15:12:06 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-06-03 20:51:08 +00:00
|
|
|
const (
|
2023-09-16 23:04:44 +00:00
|
|
|
ReleaseVersion string = "0.90.4"
|
2023-06-03 20:51:08 +00:00
|
|
|
)
|
|
|
|
|
2023-01-27 19:17:13 +00:00
|
|
|
var (
|
2023-09-12 18:06:45 +00:00
|
|
|
All bool
|
|
|
|
Audio bool
|
|
|
|
Bind string
|
|
|
|
Cache bool
|
|
|
|
CacheFile string
|
2023-09-14 22:37:22 +00:00
|
|
|
Code bool
|
2023-09-15 06:31:23 +00:00
|
|
|
CodeTheme string
|
2023-09-15 19:28:21 +00:00
|
|
|
ExitOnError bool
|
2023-09-12 18:06:45 +00:00
|
|
|
Filtering bool
|
|
|
|
Flash bool
|
2023-09-14 04:24:29 +00:00
|
|
|
Handlers bool
|
2023-09-12 18:06:45 +00:00
|
|
|
Images bool
|
2023-09-13 04:35:17 +00:00
|
|
|
Info bool
|
2023-09-15 18:53:12 +00:00
|
|
|
MaximumFileCount uint
|
|
|
|
MinimumFileCount uint
|
2023-09-12 21:46:58 +00:00
|
|
|
PageLength uint32
|
2023-09-12 18:06:45 +00:00
|
|
|
Port uint16
|
2023-09-14 04:24:29 +00:00
|
|
|
Prefix string
|
2023-09-12 18:06:45 +00:00
|
|
|
Profile bool
|
|
|
|
Recursive bool
|
2023-09-14 05:07:54 +00:00
|
|
|
Refresh bool
|
2023-09-12 18:06:45 +00:00
|
|
|
Russian bool
|
|
|
|
Sorting bool
|
|
|
|
Text bool
|
|
|
|
Verbose bool
|
|
|
|
Version bool
|
|
|
|
Videos bool
|
2022-09-08 15:12:06 +00:00
|
|
|
|
2023-01-27 19:17:13 +00:00
|
|
|
rootCmd = &cobra.Command{
|
|
|
|
Use: "roulette <path> [path]...",
|
2023-09-11 02:05:35 +00:00
|
|
|
Short: "Serves random media from the specified directories.",
|
2023-01-27 19:17:13 +00:00
|
|
|
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-05-31 18:01:24 +00:00
|
|
|
log.Fatal(err)
|
2022-09-08 15:12:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2023-09-13 04:35:17 +00:00
|
|
|
rootCmd.Flags().BoolVarP(&All, "all", "a", false, "enable all supported file types")
|
2023-09-12 18:06:45 +00:00
|
|
|
rootCmd.Flags().BoolVar(&Audio, "audio", false, "enable support for audio files")
|
|
|
|
rootCmd.Flags().StringVarP(&Bind, "bind", "b", "0.0.0.0", "address to bind to")
|
|
|
|
rootCmd.Flags().BoolVarP(&Cache, "cache", "c", false, "generate directory cache at startup")
|
|
|
|
rootCmd.Flags().StringVar(&CacheFile, "cache-file", "", "path to optional persistent cache file")
|
2023-09-14 22:37:22 +00:00
|
|
|
rootCmd.Flags().BoolVar(&Code, "code", false, "enable support for source code files")
|
2023-09-15 06:31:23 +00:00
|
|
|
rootCmd.Flags().StringVar(&CodeTheme, "code-theme", "solarized-dark256", "theme for source code syntax highlighting")
|
2023-09-15 19:28:21 +00:00
|
|
|
rootCmd.Flags().BoolVar(&ExitOnError, "exit-on-error", false, "shut down webserver on error, instead of just printing the error")
|
2023-09-12 18:06:45 +00:00
|
|
|
rootCmd.Flags().BoolVarP(&Filtering, "filter", "f", false, "enable filtering")
|
2023-09-12 19:00:15 +00:00
|
|
|
rootCmd.Flags().BoolVar(&Flash, "flash", false, "enable support for shockwave flash files (via ruffle.rs)")
|
2023-09-14 04:24:29 +00:00
|
|
|
rootCmd.Flags().BoolVar(&Handlers, "handlers", false, "display registered handlers (for debugging)")
|
2023-09-12 18:51:00 +00:00
|
|
|
rootCmd.Flags().BoolVar(&Images, "images", false, "enable support for image files")
|
2023-09-13 04:35:17 +00:00
|
|
|
rootCmd.Flags().BoolVarP(&Info, "info", "i", false, "expose informational endpoints")
|
2023-09-15 18:53:12 +00:00
|
|
|
rootCmd.Flags().UintVar(&MaximumFileCount, "maximum-files", 1<<32-1, "skip directories with file counts above this value")
|
|
|
|
rootCmd.Flags().UintVar(&MinimumFileCount, "minimum-files", 1, "skip directories with file counts below this value")
|
2023-09-15 02:13:12 +00:00
|
|
|
rootCmd.Flags().Uint32Var(&PageLength, "page-length", 0, "pagination length for info pages")
|
2023-09-12 18:06:45 +00:00
|
|
|
rootCmd.Flags().Uint16VarP(&Port, "port", "p", 8080, "port to listen on")
|
2023-09-14 05:01:50 +00:00
|
|
|
rootCmd.Flags().StringVar(&Prefix, "prefix", "/", "root path for http handlers (for reverse proxying)")
|
2023-09-12 18:06:45 +00:00
|
|
|
rootCmd.Flags().BoolVar(&Profile, "profile", false, "register net/http/pprof handlers")
|
|
|
|
rootCmd.Flags().BoolVarP(&Recursive, "recursive", "r", false, "recurse into subdirectories")
|
2023-09-14 05:07:54 +00:00
|
|
|
rootCmd.Flags().BoolVar(&Refresh, "refresh", false, "enable automatic page refresh via query parameter")
|
2023-09-12 18:06:45 +00:00
|
|
|
rootCmd.Flags().BoolVar(&Russian, "russian", false, "remove selected images after serving")
|
|
|
|
rootCmd.Flags().BoolVarP(&Sorting, "sort", "s", false, "enable sorting")
|
|
|
|
rootCmd.Flags().BoolVar(&Text, "text", false, "enable support for text files")
|
2023-09-13 04:35:17 +00:00
|
|
|
rootCmd.Flags().BoolVarP(&Verbose, "verbose", "v", false, "log accessed files and other information to stdout")
|
2023-09-12 18:06:45 +00:00
|
|
|
rootCmd.Flags().BoolVarP(&Version, "version", "V", false, "display version and exit")
|
|
|
|
rootCmd.Flags().BoolVar(&Videos, "video", false, "enable support for video files")
|
2023-09-11 02:02:03 +00:00
|
|
|
|
2022-09-10 21:17:55 +00:00
|
|
|
rootCmd.Flags().SetInterspersed(true)
|
2023-05-12 04:22:31 +00:00
|
|
|
|
|
|
|
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
|
|
|
|
|
|
|
rootCmd.SilenceErrors = true
|
|
|
|
rootCmd.SetHelpCommand(&cobra.Command{
|
|
|
|
Hidden: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
rootCmd.SetVersionTemplate("roulette v{{.Version}}\n")
|
2023-09-12 18:06:45 +00:00
|
|
|
rootCmd.Version = ReleaseVersion
|
2022-09-08 15:12:06 +00:00
|
|
|
}
|