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
|
|
|
|
|
|
|
|
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")
|
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
|
|
|
}
|
|
|
|
}
|