cmd

package
v0.6.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCMD = &cobra.Command{
	Use:   "yeet",
	Short: "yeet is an in-memory indexed static file webserver",
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		viper.SetConfigName("config")
		viper.AddConfigPath(".")
		viper.SetEnvPrefix("yeet")
		viper.AutomaticEnv()

		_ = viper.ReadInConfig()

		level, err := zerolog.ParseLevel(viper.GetString("log"))
		if err != nil {
			panic(err)
		}

		zerolog.SetGlobalLevel(level)

		writers := make([]io.Writer, 0)
		if !viper.GetBool("quiet") {
			writers = append(writers, zerolog.ConsoleWriter{
				Out:        os.Stdout,
				TimeFormat: time.RFC3339,
			})
		}

		if viper.GetString("log-file") != "" {
			logFile, err := os.OpenFile(viper.GetString("log-file"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

			if err != nil {
				return errors.Wrap(err, "failed to open log file")
			}

			writers = append(writers, logFile)
		}

		log.Logger = zerolog.New(io.MultiWriter(writers...)).With().Timestamp().Logger()

		return nil
	},
}
View Source
var ServeCMD = &cobra.Command{
	Use:   "serve",
	Short: "Serve files with yeet",
	PreRunE: func(cmd *cobra.Command, args []string) error {
		if viper.GetBool("warmup") && viper.GetBool("expiry") {
			return errors.New("expiry not supported if warmup is enabled")
		}
		return nil
	},
}

Functions

func Execute

func Execute()

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL