Resolve https://github.com/matthieugrieger/mumbledj/issues/158: Config values can now be overriden directly via commandline arguments

This commit is contained in:
Matthieu Grieger 2016-06-25 23:27:12 -07:00
parent 918c59317a
commit a44bac5302
3 changed files with 35 additions and 1 deletions

View file

@ -1,6 +1,12 @@
MumbleDJ Changelog 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` ### June 25, 2016 -- `v3.0.6`
* Fixed an issue with `!forceskip` not stopping audio playback. * Fixed an issue with `!forceskip` not stopping audio playback.

View file

@ -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 ## Commands
### add ### add

22
main.go
View file

@ -32,7 +32,7 @@ func init() {
services.DJ = DJ services.DJ = DJ
bot.DJ = DJ bot.DJ = DJ
DJ.Version = "v3.0.6" DJ.Version = "v3.0.7"
logrus.SetLevel(logrus.WarnLevel) logrus.SetLevel(logrus.WarnLevel)
} }
@ -97,11 +97,31 @@ func main() {
Usage: "if present, all debug messages will be shown", 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 { app.Action = func(c *cli.Context) error {
if c.Bool("debug") { if c.Bool("debug") {
logrus.SetLevel(logrus.InfoLevel) 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")) viper.SetConfigFile(c.String("config"))
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {
logrus.WithFields(logrus.Fields{ logrus.WithFields(logrus.Fields{