-
-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Viper to manage the configuration file #487
Conversation
return fmt.Errorf("getting hardware directory: %s", err) | ||
} | ||
|
||
dirs = configuration.BundleToolsDirectories() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the error was removed because these functions always returned nil
cmd.PersistentFlags().StringVar(&globals.LogLevel, "log-level", defaultLogLevel, "Messages with this level and above will be logged.") | ||
cmd.PersistentFlags().StringVar(&logFile, "log-file", "", "Path to the file where logs will be written.") | ||
cmd.PersistentFlags().StringVar(&logFormat, "log-format", "text", "The output format for the logs, can be [text|json].") | ||
cmd.PersistentFlags().String("log-level", "", "Messages with this level and above will be logged.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need a var anymore since the flag value is stored in the settings objects directly (this applies to following similar cases)
// configure logging filter | ||
if lvl, found := toLogLevel(globals.LogLevel); !found { | ||
fmt.Printf("Invalid option for --log-level: %s", globals.LogLevel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated but we should use feedback
instead of fmt
across the codebase
* otherwise use the software for commercial activities involving the Arduino | ||
* software without disclosing the source code of your own applications. To purchase | ||
* a commercial license, send an email to [email protected]. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated but we should uniform license format when we find inconsistencies
6439d3a
to
98dbc20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, a lot.
We did not lose anything in flexibility and cleaned up a lot of boilerplate, while maintaining retrocompatibility.
) | ||
|
||
// Navigate FIXMEDOC | ||
func (c *Configuration) Navigate(pwd *paths.Path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does viper provides a Navigate
feature already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call viper.AddConfigPath()
several times passing the path where Viper should look for a config file
|
||
builderCtx.OtherLibrariesDirs = paths.NewPathList() | ||
builderCtx.OtherLibrariesDirs.Add(config.LibrariesDir()) | ||
builderCtx.OtherLibrariesDirs.Add(paths.New(viper.GetString("directories.Libraries"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not put viper.GetString("directories.Libraries")
into an helper function? like as you did with configuration.HardwareDirectories()
for example?
At this point I'd write an helper function for each key we put in viper, doing so will enforce a more strict compile-time checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the reasons to switch to Viper was having a generic k/v store that can arbitrarily grow without the need to change the API. I understand the issue of losing the check on the configuration keys at compile time (if you write viper.GetString("directories.Libs")
the program will happily compile despite not working as expected) but I think the tradeoff is worth it. We can catch errors on configuration keys at unit test time.
} | ||
|
||
// LoadFromDesktopIDEPreferences loads the config from the Desktop IDE preferences.txt file | ||
func (config *Configuration) LoadFromDesktopIDEPreferences() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we dropping loading/overlaying options from the IDE preferences.txt
? (just asking I may be OK with that :-))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I didn't fully get what this was for - I'd say let's get rid of it.
If needed, I'd add a specific command like arduino-cli config import /path/to/preferences.txt
so the operation is explicit.
introduce viper
revert format formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR introduces https://github.com/spf13/viper to manage the configuration file in order to:
An example of configuration file would look like this:
A new package,
configuration
, has been added to:I've left inline comments to ease the review process.