-
-
Notifications
You must be signed in to change notification settings - Fork 362
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
Conversation
payload *downloadPayload | ||
} | ||
|
||
func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, 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.
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.
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.
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 |
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 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.
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 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 { |
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 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.
b40b413
to
d5ffa73
Compare
Unneeded as these checks already happen in the constructor and it's potentially confusing because there are other needsX validation methods
Sweet! I'll look at this today. This looks like a very manageable size to review, I appreciate that very much 💙 💚 💛 |
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 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 |
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 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) { |
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.
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 { |
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 an attempt at a minimal first change in refactoring the download command. This change adds a download type.