Migrer déclaration de flags à serpents

This commit is contained in:
Victor Lacasse-Beaudoin 2023-10-18 16:22:35 -04:00
parent ad3faf98c5
commit d694defa18

View file

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