-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add -config flag #18
Add -config flag #18
Conversation
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 will make some commits to later to fix some things probably. Thanks again btw for sharing this idea, it's really good. I definitely want to implement it.
case 2: | ||
cmd = os.Args[1] | ||
case 4: | ||
cmd = os.Args[3] |
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 is something I'm not a huge fan of; because it's guessing whether the config flag comes before or after the command.
func ReadConfig(config_path string) (Config, error) { | ||
var config Config | ||
configPath := getConfigPath() | ||
configPath := getConfigPath(config_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.
In Golang I use camelCase instead of underscores for variables (as is mentioned in Google's style guide).
func getConfigPath(config_path string) string { | ||
if FileExists(config_path) { | ||
return config_path | ||
} else { | ||
dirname, _ := os.UserHomeDir() | ||
return dirname + "/.mdrss/config.json" | ||
} |
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 check for the existence of the config path later in the code. Here I just select / construct the config path that I want to use. Hence. the first if statement should only check whether the config path from the flag is enabled.
(PS: it should not be called configPath yet, because we don't know whether it is even used at this point. It's really the config path flag).
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'd also add that XDG should be used. So this should be ~/.config/mdrss/config.json
.
Instead of:
dirname, _ := os.UserHomeDir()
return dirname + "/.mdrss/config.json"
you can use adrg/xdg:
configFilePath, err := xdg.ConfigFile("mdrss/config.json")
if err != nil {
log.Fatal(err)
}
return configFilePath
Hi @TimoKats, I'll leave the PR in your hands to change the way you like before merge. |
Hi @yonas . Thanks will do |
Allow users to specify path to
config.json
.