-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Prompt for country on first run and save to config file #30
Conversation
} | ||
|
||
err = getGridIntensityForCountry(country) | ||
err := runWithError() |
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 extracted the logic to this function which simplifies the error handling. So we only need a single log.Fatal call.
@@ -50,30 +51,92 @@ func Execute() { | |||
|
|||
func init() { | |||
rootCmd.Flags().StringP(countryCode, "c", "", "Country code in ISO 3 character format") | |||
viper.BindPFlag(countryCode, rootCmd.Flags().Lookup(countryCode)) |
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 how we add viper for managing the config by binding it to the cobra CLI flag.
if countryCode == "" { | ||
// No country code provided so try to detect it from the user's locale. | ||
tag, err := locale.Detect() | ||
result, err := ember.GetGridIntensityForCountry(countryCode) |
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.
Sorry the diff is a bit hard to follow here. All the logic for getting the country code is moved to the getCountryCode func.
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'm happy for this to be merged in @rossf7.
There's only one query I have here when we prompt users for a country code.
However, I'm ok with us splitting that out as a separate issue, and for us to it to talk about the first time experience across all the providers we currently use.
viper.Set(countryCode, country) | ||
} | ||
|
||
err = getGridIntensityForCountry(country) |
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.
Do you think it's worth making explicit that the country code is being used to make the request/lookup against our set of country / carbon intensity codes?
I know the returned JSON blob mentions that the country and country code, but for the first time, when I looked over it, I felt like having a short one line outlining what was about to happen before showing the returned value would make it easier to understand what was happening.
This probably isn't needed on subsequent uses, but I think it provides a more gentle way into this domain.
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.
Yes, I agree I think we should explain more what is going on.
I've been thinking we could add an --output
flag that defaults to text but also supports JSON.
The text output could walk the user through choosing a provider and region. As well as linking to our developer site for more docs. WDYT?
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.
yes. would you mind creating an issue for this? I think this would be a good one to include Fershad for this, so he can create some tutorials and add some reference to it in the developers.tgwf site
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.
@mrchrisadams I created #32 for this. I agree it would be good to work with Fershad on this and to have some tutorials.
Thanks @mrchrisadams I'm going to merge this. I'll create a new issue for the first time experience. |
Towards #16
On first run we now check if the config file
~/.config/grid-intensity/config.yaml
exists.If not the user is prompted to enter a country code. We still show the country from the user's locale as a hint.
Running a 2nd time the saved setting is used.
Specifying a country code will save the new value.