depot/web/fup/cmd/root.go

45 lines
793 B
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
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")
}
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())
}
}