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

[WIP] Add doctor cmd - migrate legacy exercises #744

Closed
wants to merge 3 commits into from

Conversation

jdsutherland
Copy link
Contributor

@jdsutherland jdsutherland commented Sep 27, 2018

Closes #639
Closes 699 - decided clean up numeric suffixes should be split into separate PR.

Still a rough WIP.

* Passing
* Copied most of download#runDownload. Payload download seems like it
needs extracted out of cmd/download.
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.

Thanks for starting on this one! I left a couple of comments about the direction. 🌸


func setupDoctorFlags(flags *pflag.FlagSet) {
flags.BoolP("fixup", "f", false, "run tasks")
// TODO: --dry-run for fixup
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need both --dry-run and --fixup. Originally I was thinking that running doctor bare would fix things, and in that case we'd need --dry-run to just do reporting. With this approach we're reversing the logic, so that doctor bare does the reporting, which means that we need a flag (--fixup) to make the actual changes.


// TODO: extract this and cmd/download into download service?
// copied from download#runDownload
func downloadMetadata(exercise workspace.Exercise, cfg config.Config) error {
Copy link
Member

Choose a reason for hiding this comment

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

unexported functions are available in the entire cmd package. We don't need to copy it, just extract it.

Copy link
Contributor Author

@jdsutherland jdsutherland Oct 8, 2018

Choose a reason for hiding this comment

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

Right. I wasn't suggesting that it was necessary to duplicate the function within the same package. I was trying to point out that runDownload currently has duplicate behavior that we're going to want to use in doctor but we can't use the existing function (because we only need metadata whereas this function also writes all solution files). It seems that the logic for getting a downloadPayload should be extracted outside of the cmd package (given that multiple cmd's use it) with separate functions for writing metadata and solution files. I'm wondering if #719 is related.

If #719 doesn't cover this, where would you suggest these extractions live?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that it should live outside the cmd package, if only commands need it.

The code in api is very generic, whereas this is pretty specific.

I'd stick the extracted logic in cmd/cmd.go for now.

Copy link
Contributor Author

@jdsutherland jdsutherland Oct 28, 2018

Choose a reason for hiding this comment

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

Only the commands need it but it seems more like a service than an actual command and currently everything in the cmd package is a command. It also seems conceivable that something other than cmd might want to consume it.

The download payload stuff could go in cmd/cmd as a tacit home for shared command functionality or it could be put into a new 'helper/util' file. Maybe that's fine but it seems like it would be an outlier, so that's the rationale for considering putting it outside.

I gave a shot at the refactoring in #756

fixup, err := flags.GetBool("fixup")
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

In terms of design, what I think would help make it easy to do both modes (reporting and fixing), would be to have a type for each type of thing we're fixing. We can initialize the value, and have three different steps:

  1. Investigate.
  2. Report.
  3. Fix.

The investigation would store whatever it needs to make it easy to both report and fix.

@jdsutherland jdsutherland changed the title [WIP] Add doctor cmd [WIP] Add doctor cmd - migrate legacy exercises Dec 12, 2018
@jdsutherland
Copy link
Contributor Author

I don't anticipate completing this so I'm going to close it.

@kytrinyx
Copy link
Member

kytrinyx commented Mar 8, 2019

Ok, thank you @jdsutherland.

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.

Implement behavior to migrate legacy exercises on the filesystem
2 participants