Skip to content
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

Extract download type from download command #821

Merged
merged 2 commits into from
Feb 28, 2019

Conversation

jdsutherland
Copy link
Contributor

This is an attempt at a minimal first change in refactoring the download command. This change adds a download type.

payload *downloadPayload
}

func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently longer than ideal. I think it makes sense to have the logic to populate the payload in the constructor though. Clients can't do anything with a download without the payload being populated and extracting it to a method doesn't seem appropriate because clients should never need to call it - it just needs to happen on creation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would either have to be populated in the constructor, or have a separate method that always gets called before we need those values. The second seems like an unnecessary abstraction.

slug, uuid string

// user config
token, apibaseurl, workspace string
Copy link
Contributor Author

@jdsutherland jdsutherland Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if most would agree to save these an individual fields rather than the config object. Calling GetString throughout the system seems vulnerable to typo's where using fields has the benefit of the compiler catching it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually really like having them here like that. The flags feel like they should be processed once, and that's it.

}

// needsUserConfigValues checks the presence of required values from the user config.
func (d download) needsUserConfigValues() error {
Copy link
Contributor Author

@jdsutherland jdsutherland Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cmd/cmd we have func validateUserConfig(cfg *viper.Viper) but coupling to an outside validation seems like a bad idea so that's why it's duplicated here.

Unneeded as these checks already happen in the constructor and it's
potentially confusing because there are other needsX validation methods
@kytrinyx
Copy link
Member

Sweet! I'll look at this today. This looks like a very manageable size to review, I appreciate that very much 💙 💚 💛

Copy link
Member

@kytrinyx kytrinyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much, much better! Thanks for your patience with my OSS maintainership snafus and hanging in there while I was AWOL.

slug, uuid string

// user config
token, apibaseurl, workspace string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually really like having them here like that. The flags feel like they should be processed once, and that's it.

payload *downloadPayload
}

func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would either have to be populated in the constructor, or have a separate method that always gets called before we need those values. The second seems like an unnecessary abstraction.

}
defer res.Body.Close()

if err := json.NewDecoder(res.Body).Decode(&d.payload); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible (or useful) to use the error parser?

cli/cmd/cmd.go

Line 78 in c3525cf

func decodedAPIError(resp *http.Response) error {

I cherry-picked your commit here #814

If so, let's do that as the next PR (I'm going to merge this one, as it looks great).

@kytrinyx kytrinyx merged commit 448ce88 into exercism:master Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants