Merge pull request 'Migrer déclaration de flags à serpents' (#26) from refactor/serpents into main

Reviewed-on: #26
This commit is contained in:
Victor Lacasse-Beaudoin 2023-10-18 15:29:54 -05:00
commit c3a943546b

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"codeberg.org/vlbeaudoin/serpents"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -31,102 +32,94 @@ func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.bottin-agenda.yaml)") rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.bottin-agenda.yaml)")
// web.api.host // web.api.host
rootCmd.PersistentFlags().String( serpents.String(rootCmd.PersistentFlags(),
"web-api-host", "api", "web.api.host", "web-api-host", "api",
"Remote API server host (config:'web.api.host')") "Remote API server host")
viper.BindPFlag("web.api.host", rootCmd.PersistentFlags().Lookup("web-api-host"))
// web.api.key // web.api.key
rootCmd.PersistentFlags().String( serpents.String(rootCmd.PersistentFlags(),
"web-api-key", "bottin-agenda", "web.api.key", "web-api-key", "bottin-agenda",
"Remote API server key (config:'web.api.key')") "Remote API server key")
viper.BindPFlag("web.api.key", rootCmd.PersistentFlags().Lookup("web-api-key"))
// web.api.protocol // web.api.protocol
rootCmd.PersistentFlags().String( serpents.String(rootCmd.PersistentFlags(),
"web-api-protocol", "http", "web.api.protocol", "web-api-protocol", "http",
"Remote API server protocol (config:'web.api.protocol')") "Remote API server protocol")
viper.BindPFlag("web.api.protocol", rootCmd.PersistentFlags().Lookup("web-api-protocol"))
// web.api.port // web.api.port
rootCmd.PersistentFlags().Int( serpents.Int(rootCmd.PersistentFlags(),
"web-api-port", 1313, "web.api.port", "web-api-port", 1313,
"Remote API server port (config:'web.api.port')") "Remote API server port")
viper.BindPFlag("web.api.port", rootCmd.PersistentFlags().Lookup("web-api-port"))
// web.password // web.password
rootCmd.PersistentFlags().String( serpents.String(rootCmd.PersistentFlags(),
"web-password", "bottin-agenda", "web.password", "web-password", "bottin-agenda",
"Web client password (config:'web.password')") "Web client password")
viper.BindPFlag("web.password", rootCmd.PersistentFlags().Lookup("web-password"))
// web.port // web.port
rootCmd.PersistentFlags().Int( serpents.Int(rootCmd.PersistentFlags(),
"web-port", 2313, "web.port", "web-port", 2313,
"Web client port (config:'web.port')") "Web client port")
viper.BindPFlag("web.port", rootCmd.PersistentFlags().Lookup("web-port"))
// web.user // web.user
rootCmd.PersistentFlags().String( serpents.String(rootCmd.PersistentFlags(),
"web-user", "bottin-agenda", "web.user", "web-user", "bottin-agenda",
"Web client user (config:'web.user')") "Web client user")
viper.BindPFlag("web.user", rootCmd.PersistentFlags().Lookup("web-user"))
// api.key // api.key
rootCmd.PersistentFlags().String( serpents.String(rootCmd.PersistentFlags(),
"api-key", "bottin-agenda", "api.key", "api-key", "bottin-agenda",
"API server key. Leave empty for no key auth. (config: 'api.key')") "API server key. Leave empty for no key auth.")
viper.BindPFlag("api.key", rootCmd.PersistentFlags().Lookup("api-key"))
// api.port // api.port
rootCmd.PersistentFlags().Int( serpents.Int(rootCmd.PersistentFlags(),
"api-port", 1313, "api.port", "api-port", 1313,
"API server port (config:'api.port')") "API server port")
viper.BindPFlag("api.port", rootCmd.PersistentFlags().Lookup("api-port"))
// bottin.api.host // bottin.api.host
rootCmd.PersistentFlags().String( serpents.String(rootCmd.PersistentFlags(),
"bottin-api-host", "api", "bottin.api.host", "bottin-api-host", "api",
"Remote bottin API server host (config:'bottin.api.host')") "Remote bottin API server host")
viper.BindPFlag("bottin.api.host", rootCmd.PersistentFlags().Lookup("bottin-api-host"))
// bottin.api.key // bottin.api.key
rootCmd.PersistentFlags().String( serpents.String(rootCmd.PersistentFlags(),
"bottin-api-key", "bottin", "bottin.api.key", "bottin-api-key", "bottin",
"Remote bottin API server key (config:'bottin.api.key')") "Remote bottin API server key")
viper.BindPFlag("bottin.api.key", rootCmd.PersistentFlags().Lookup("bottin-api-key"))
// bottin.api.protocol // bottin.api.protocol
rootCmd.PersistentFlags().String( serpents.String(rootCmd.PersistentFlags(),
"bottin-api-protocol", "http", "bottin.api.protocol", "bottin-api-protocol", "http",
"Remote bottin API server protocol (config:'bottin.api.protocol')") "Remote bottin API server protocol")
viper.BindPFlag("bottin.api.protocol", rootCmd.PersistentFlags().Lookup("bottin-api-protocol"))
// bottin.api.port // bottin.api.port
rootCmd.PersistentFlags().Int( serpents.Int(rootCmd.PersistentFlags(),
"bottin-api-port", 1312, "bottin.api.port", "bottin-api-port", 1312,
"Remote bottin API server port (config:'bottin.api.port')") "Remote bottin API server port")
viper.BindPFlag("bottin.api.port", rootCmd.PersistentFlags().Lookup("bottin-api-port"))
// db.database // db.database
rootCmd.PersistentFlags().String("db-database", "bottin-agenda", "Postgres database (config:'db.database')") serpents.String(rootCmd.PersistentFlags(),
viper.BindPFlag("db.database", rootCmd.PersistentFlags().Lookup("db-database")) "db.database", "db-database", "bottin-agenda",
"Postgres database")
// db.host // db.host
rootCmd.PersistentFlags().String("db-host", "db", "Postgres host (config:'db.host')") serpents.String(rootCmd.PersistentFlags(),
viper.BindPFlag("db.host", rootCmd.PersistentFlags().Lookup("db-host")) "db.host", "db-host", "db",
"Postgres host")
// db.password // db.password
rootCmd.PersistentFlags().String("db-password", "bottin-agenda", "Postgres password (config:'db.password')") serpents.String(rootCmd.PersistentFlags(),
viper.BindPFlag("db.password", rootCmd.PersistentFlags().Lookup("db-password")) "db.password", "db-password", "bottin-agenda",
"Postgres password")
// db.port // db.port
rootCmd.PersistentFlags().Int("db-port", 5432, "Postgres port (config:'db.port')") serpents.Int(rootCmd.PersistentFlags(),
viper.BindPFlag("db.port", rootCmd.PersistentFlags().Lookup("db-port")) "db.port", "db-port", 5432,
"Postgres port")
// db.user // db.user
rootCmd.PersistentFlags().String("db-user", "bottin-agenda", "Postgres user (config:'db.user')") serpents.String(rootCmd.PersistentFlags(),
viper.BindPFlag("db.user", rootCmd.PersistentFlags().Lookup("db-user")) "db.user", "db-user", "bottin-agenda",
"Postgres user")
} }
// initConfig reads in config file and ENV variables if set. // initConfig reads in config file and ENV variables if set.