depot/web/fup/cmd/root.go
Luke Granger-Brown 25443cfaab fup: add bucket-url flag for specifying storage
This allows setting the persistent storage location to save files into.

NOTE: defaults to mem:// for development purposes, which... is gonna be a bad
time.
2021-03-20 23:33:39 +00:00

48 lines
1 KiB
Go

// SPDX-FileCopyrightText: 2021 Luke Granger-Brown <depot@lukegb.com>
//
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
cfgFile string
bucketURL string
rootCmd = &cobra.Command{
Use: "fup",
Short: "fup is a minimalistic file server.",
Long: "fup handles uploads and downloads of content.",
}
)
func Execute() error {
return rootCmd.Execute()
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
rootCmd.PersistentFlags().StringVar(&bucketURL, "bucket-url", "mem://", "gocloud.dev-compatible URL to use for file storage")
viper.BindPFlag("storage.bucketURL", rootCmd.PersistentFlags().Lookup("bucket-url"))
}
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())
}
}