depot/web/fup/cmd/root.go

51 lines
1.1 KiB
Go
Raw Normal View History

2021-03-20 20:40:40 +00:00
// SPDX-FileCopyrightText: 2021 Luke Granger-Brown <depot@lukegb.com>
//
// SPDX-License-Identifier: Apache-2.0
2021-03-20 19:49:33 +00:00
package cmd
import (
2021-03-20 23:32:56 +00:00
"log"
2021-03-20 19:49:33 +00:00
"github.com/spf13/cobra"
2021-03-20 23:32:56 +00:00
"github.com/spf13/viper"
2021-03-20 19:49:33 +00:00
)
2021-03-20 23:32:56 +00:00
var (
cfgFile string
2021-03-20 23:32:56 +00:00
rootCmd = &cobra.Command{
Use: "fup",
Short: "fup is a minimalistic file server.",
Long: "fup handles uploads and downloads of content.",
}
)
func bucketURL() string { return viper.GetString("storage.bucketURL") }
2021-03-20 23:32:56 +00:00
func Execute() error {
return rootCmd.Execute()
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
rootCmd.PersistentFlags().String("bucket-url", "mem://", "gocloud.dev-compatible URL to use for file storage")
viper.BindPFlag("storage.bucketURL", rootCmd.PersistentFlags().Lookup("bucket-url"))
viper.SetDefault("storage.bucketURL", "mem://")
2021-03-20 19:49:33 +00:00
}
2021-03-20 23:32:56 +00:00
func initConfig() {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
}
viper.SetEnvPrefix("fup")
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err == nil {
log.Printf("Using config file: %v", viper.ConfigFileUsed())
2021-03-20 19:49:33 +00:00
}
}