From a44bac5302d28ce39d4a079ffad7d422cb36ba35 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Sat, 25 Jun 2016 23:27:12 -0700 Subject: [PATCH] Resolve https://github.com/matthieugrieger/mumbledj/issues/158: Config values can now be overriden directly via commandline arguments --- CHANGELOG.md | 6 ++++++ README.md | 8 ++++++++ main.go | 22 +++++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67e8cbd..e5c3c3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ MumbleDJ Changelog ================== +### June 25, 2016 -- `v3.0.7` +* Volume can now be set to `volume.lowest` and `volume.highest` (in other words, the range is inclusive now instead of exclusive). +* All configuration values can now be overriden via commandline arguments. For example: `mumbledj --admins.names="SuperUser,Matt" --volume.default="0.5" --commands.add.is_admin="false"` + * __NOTE__: Configuration settings that contain commas (",") are interpreted as string slices (or arrays if you aren't familiar with Go). +* Removed an extra period that was sometimes output in error messages. + ### June 25, 2016 -- `v3.0.6` * Fixed an issue with `!forceskip` not stopping audio playback. diff --git a/README.md b/README.md index 776a6ae..50b59d2 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,14 @@ GLOBAL OPTIONS: ``` +__NOTE__: You can also override all settings found within `config.yaml` directly from the commandline. Here's an example: + +``` +mumbledj --admins.names="SuperUser,Matt" --volume.default="0.5" --volume.lowest="0.2" --queue.automatic_shuffle_on="true" +``` + +Keep in mind that values that contain commas (such as `"SuperUser,Matt"`) will be interpreted as string slices, or arrays if you are not familiar with Go. If you want your value to be interpreted as a normal string, it is best to avoid commas for now. + ## Commands ### add diff --git a/main.go b/main.go index c53ce02..7e14d35 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ func init() { services.DJ = DJ bot.DJ = DJ - DJ.Version = "v3.0.6" + DJ.Version = "v3.0.7" logrus.SetLevel(logrus.WarnLevel) } @@ -97,11 +97,31 @@ func main() { Usage: "if present, all debug messages will be shown", }, } + + hiddenFlags := make([]cli.Flag, len(viper.AllKeys())) + for i, configValue := range viper.AllKeys() { + hiddenFlags[i] = cli.StringFlag{ + Name: configValue, + Hidden: true, + } + } + app.Flags = append(app.Flags, hiddenFlags...) + app.Action = func(c *cli.Context) error { if c.Bool("debug") { logrus.SetLevel(logrus.InfoLevel) } + for _, configValue := range viper.AllKeys() { + if c.GlobalIsSet(configValue) { + if strings.Contains(c.String(configValue), ",") { + viper.Set(configValue, strings.Split(c.String(configValue), ",")) + } else { + viper.Set(configValue, c.String(configValue)) + } + } + } + viper.SetConfigFile(c.String("config")) if err := viper.ReadInConfig(); err != nil { logrus.WithFields(logrus.Fields{