-
-
Notifications
You must be signed in to change notification settings - Fork 363
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
improve open cmd #788
improve open cmd #788
Conversation
1c1c997
to
d0c429f
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 think this is ready for review now, I've made the changes I feel best for consistency with the download command. I'll add tests after it's reviewed to make sure everything is how we want.
cmd/open.go
Outdated
continue | ||
} | ||
|
||
if meta.Team != teamID { |
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.
Initially, I tried teamID != "" && meta.Team != teamID
, but the current boolean statement is more in line with how the api handles team exercises.
@@ -0,0 +1 @@ | |||
package cmd |
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 like to add tests after this is reviewed, to check that functionality is how we want it
workspace/workspace.go
Outdated
@@ -57,6 +57,16 @@ func (ws Workspace) PotentialExercises() ([]Exercise, error) { | |||
continue | |||
} | |||
|
|||
if topInfo.Name() == "teams" { |
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 needed to add support for teams to PotentialExercises
as before this change, it doesn't find them
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.
Would you mind extracting this change into a separate PR? (We should probably include tests for the change).
I completely failed to keep up with my Exercism notifications, and I'm inexcusably late to the party. To add to this, my laptop crashed and is now in for repair, and as of today I have a loaner that I've not quite gotten set up to be usable. So. My apologies (first) and (second)... my goal is to get through all the open PRs in the CLI track over the course of the next week. So sorry to leave you hanging! |
Don't worry about it too much! Things happen and I'm pretty sure most people here are guilty of ignoring notifications for a long time. Completely understandable |
Hey @Smarticles101 -- overall it looks like what you have here is much better. In order to help me review this properly, would you summarize exactly what changed, and how this will change the usage of the command? |
@kytrinyx
The new command, rather than using an exercise path, follows a style similar to the other commands. Now instead of passing an exercise directory, you pass a slug.
I also added support for |
Thank you, that's really helpful! In order to not break people's work flow we'll need to support the original usage as well, though... at least until we do a major version bump. |
@kytrinyx That sounds good, I can add that back in when I have free time tomorrow |
@kytrinyx original usage is supported now :) |
No idea why the build is failing, I haven't changed anything that should make it fail, and I've rebased against master and compiled it locally and it seems to work? |
w000p!!!!
I'll take a look. |
cmd/open.go
Outdated
return err | ||
} | ||
|
||
if meta.Exercise != exerciseID { |
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 needs to be meta.ExerciseSlug
to pass the tests (see #815)
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 looking really good. I have a few suggestions, but overall I think this is doing the right thing!
cmd/open.go
Outdated
usrCfg := cfg.UserViperConfig | ||
trackID, _ := flags.GetString("track") | ||
exerciseID, _ := flags.GetString("exercise") | ||
teamID, _ := flags.GetString("team") |
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 know error checking seems tedious, but I'd rather we did it for completion. If it gets really bad we can extract it into a validator type, but for now let's just do it inline.
cmd/open.go
Outdated
var url string | ||
usrCfg := cfg.UserViperConfig | ||
trackID, _ := flags.GetString("track") | ||
exerciseID, _ := flags.GetString("exercise") |
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.
Let's name this exerciseSlug
for consistency with the rest of the codebase (we don't currently call it exerciseID anywhere).
cmd/open.go
Outdated
usrCfg := cfg.UserViperConfig | ||
trackID, _ := flags.GetString("track") | ||
exerciseID, _ := flags.GetString("exercise") | ||
teamID, _ := flags.GetString("team") |
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.
Cat we go with just team
as the variable name? We don't call this teamID anywhere else.
cmd/open.go
Outdated
metadata, err := workspace.NewExerciseMetadata(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
browser.Open(metadata.URL) | ||
return nil | ||
}, | ||
//return fmt.Errorf("Must provide an `--exercise`") |
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.
Let's ✂️ the commented out stuff.
cmd/open.go
Outdated
teamID, _ := flags.GetString("team") | ||
|
||
if exerciseID == "" { | ||
// if no --exercise is given, use original functionality | ||
metadata, err := workspace.NewExerciseMetadata(args[0]) |
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.
How about extracting args[0]
into a variable path
up at the start where we're also extracting from flags?
var path string
if args.length > 0 {
path = args[0]
}
That way down here we can say if path != "" {
If we want to be really explicit, we could also have a validation on path != "" and exerciseSlug != ""
and explain that you need one or the other.
cmd/open.go
Outdated
//return fmt.Errorf("Must provide an `--exercise`") | ||
} | ||
|
||
if remote, _ := flags.GetBool("remote"); remote { |
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.
Let's extract the remote flag up top as well, and check the error.
var payload openPayload | ||
if err := json.NewDecoder(res.Body).Decode(&payload); err != nil { | ||
return fmt.Errorf("unable to parse API response - %s", err) | ||
} |
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.
Would it make sense to use the api error decoder helper?
Line 78 in c3525cf
func decodedAPIError(resp *http.Response) 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.
I need to decode the json anyways for the solution url. The helper only returns the error. Would it be beneficial to introduce a helper that decodes the entire api response?
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.
Hm. Maybe, but let's hold off on that for now.
|
||
if res.StatusCode != http.StatusOK { | ||
switch payload.Error.Type { | ||
case "track_ambiguous": |
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 wonder if we can make the error decoder helper smarter and add this logic into it.
Line 78 in c3525cf
func decodedAPIError(resp *http.Response) error { |
(If so, let's do that in a separate PR and get that into master quickly so we can use it elsewhere).
} | ||
} | ||
|
||
url = payload.Solution.URL |
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.
Let's open the URL and return here so that we can out-dent the else
.
workspace/workspace.go
Outdated
@@ -57,6 +57,16 @@ func (ws Workspace) PotentialExercises() ([]Exercise, error) { | |||
continue | |||
} | |||
|
|||
if topInfo.Name() == "teams" { |
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.
Would you mind extracting this change into a separate PR? (We should probably include tests for the change).
0ef90c5
to
4f9bb94
Compare
I made a mess of my git tree today and ended up having to cherry-pick my commits out. I updated it to use |
@Smarticles101 just a quick note to say that I think the next step here is to rebase onto master before I do another review. If I'm wrong about that please let me know :-) |
now you just give the exercise name instead of path
4f9bb94
to
a80741c
Compare
@Smarticles101 Is this ready for another round of review? |
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 current logic around path or slug is a bit confusing, so I've suggested an improvement there.
We're also going to need to fix the long description for the command.
return fmt.Errorf("must provide an --exercise slug or an exercise path") | ||
} | ||
// if no --exercise is given, use original functionality | ||
metadata, err := workspace.NewExerciseMetadata(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.
I think that this would be easier to understand if we did something like this:
if exerciseSlug == "" && path == "" {
return fmt.Errorf...
}
if path != "" {
// get metadata and open the url
}
// etc
fd60095
to
d0d0655
Compare
I know it's been nearly two years, but I thought I would get this finished up. I've addressed the last changes requested. If everything looks good I will write some tests. |
@ekingery if you'd like to take a look at this and let me know if you see anything that's off, I'd appreciate it :) |
Thanks @Smarticles101! We're fully focused on getting configlet updated for V3 right now, but this change looks like something we should be able to get merged as soon as we can bring some focus back to the CLI and get a new version out. It looks like the build is broken at the moment, any ideas on that? |
This is quite an old PR and has some merge conflicts. @Smarticles101 do you still want to work on this? |
@ErikSchierboom thanks for checking on this. I've been out of the loop of exercism for a few years and recently started my first full-time job out of college so I don't have much time to pick this up again. I'll go ahead and close this. If anyone comes across this in the future, feel free to keep working on it :) |
This pull request aims to improve the open command.
I start by solving #460, while diving into the open command, I found that it could be improved in a few various ways.