panel/cmd/root.go

68 lines
1.7 KiB
Go
Raw Normal View History

2024-11-03 21:33:08 +01:00
/*
Package cmd
Copyright © 2024 Shane C. <shane@scaffoe.com>
*/
package cmd
import (
"embed"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
)
var cfgFile string
//go:embed templates/*
var templates embed.FS
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "omnibill",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
Run: func(cmd *cobra.Command, args []string) {
},
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.omnibill.toml)")
2024-11-03 21:33:08 +01:00
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
// All my homies hate yaml, lol.
2024-11-03 21:33:08 +01:00
viper.SetConfigType("toml")
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
viper.AddConfigPath("/etc/omnibill")
viper.SetConfigName("config")
}
viper.AutomaticEnv() // read in environment variables that match
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}