Added constants for app name and version, use custom user-agent

This commit is contained in:
Philipp Wolfer 2023-11-24 08:58:31 +01:00
parent f6b4ea4a46
commit 46e6a667c8
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
10 changed files with 75 additions and 6 deletions

View file

@ -23,17 +23,18 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uploadedlobster.com/scotty/internal/version"
)
var cfgFile string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "scotty",
Use: version.AppName,
Short: "Beam data between music listening services",
Long: `Scotty transfers your listens/scrobbles between ListenBrainz and
various other listening and streaming services.`,
Version: "0.1.0",
Version: version.AppVersion,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
@ -67,7 +68,7 @@ func init() {
func defaultConfigDir() string {
configDir, err := os.UserConfigDir()
cobra.CheckErr(err)
return path.Join(configDir, "scotty")
return path.Join(configDir, version.AppName)
}
// initConfig reads in config file and ENV variables if set.
@ -78,7 +79,7 @@ func initConfig() {
} else {
viper.AddConfigPath(defaultConfigDir())
viper.SetConfigType("toml")
viper.SetConfigName("scotty")
viper.SetConfigName(version.AppName)
}
viper.AutomaticEnv() // read in environment variables that match