Skip to content
This repository has been archived by the owner on Jan 20, 2021. It is now read-only.

Commit

Permalink
Resolve #158: Config values can now be overriden directly via command…
Browse files Browse the repository at this point in the history
…line arguments
  • Loading branch information
matthieugrieger committed Jun 26, 2016
1 parent 918c593 commit a44bac5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit a44bac5

Please sign in to comment.