-
-
Notifications
You must be signed in to change notification settings - Fork 841
Warning for nonsense variables in config #7181
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import ( | |
| "os/exec" | ||
| "path/filepath" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/dolthub/go-mysql-server/sql" | ||
|
|
@@ -461,6 +462,24 @@ func runMain() int { | |
| return 1 | ||
| } | ||
|
|
||
| globalConfig.Iter(func(name, val string) (stop bool) { | ||
| if _, ok := commands.ConfigOptions[name]; !ok && !strings.HasPrefix(name, env.SqlServerGlobalsPrefix) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (minor) Might be worth running |
||
| cli.Println(color.YellowString("Warning: Unknown global config option '%s'. Use `dolt config --global --unset %s` to remove.", name, name)) | ||
| } | ||
| return false | ||
| }) | ||
|
|
||
| // try verifying contents of local config | ||
| localConfig, ok := dEnv.Config.GetConfig(env.LocalConfig) | ||
| if ok { | ||
| localConfig.Iter(func(name, val string) (stop bool) { | ||
| if _, ok := commands.ConfigOptions[name]; !ok && !strings.HasPrefix(name, env.SqlServerGlobalsPrefix) { | ||
| cli.Println(color.YellowString("Warning: Unknown local config option '%s'. Use `dolt config --local --unset %s` to remove.", name, name)) | ||
| } | ||
| return false | ||
| }) | ||
| } | ||
|
|
||
| apr, remainingArgs, subcommandName, err := parseGlobalArgsAndSubCommandName(globalConfig, args) | ||
| if err == argparser.ErrHelp { | ||
| doltCommand.PrintUsage("dolt") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since anytime a new config value constant is added it'll need to be added to this map (i.e. high coupling), it's a good hint that these two pieces of code might benefit from being very close together. Try moving this map into the same file as where the config constants are defined.
There's another common Go trick for maps where you don't care about the values... you'll often see them written as:
The advantage to that form is that it's unambiguous to future code readers (once you know this pattern at least) that the value of the map is ignored. If you use
boolorstring, then future code readers may think that the value has some meaning. It is also slightly more efficient for the runtime to store these, because there's an optimization where Go knows empty structs don't need to be allocated anywhere, as opposed to a bool or a string, which does require allocation, even if they are empty/false. It's a small efficiency gain, but worth knowing about, especially since you'll see this pattern fairly often.