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

download: Infer track and exercise slug from CWD #880

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

petertseng
Copy link
Member

@petertseng petertseng commented Sep 15, 2019

I think this PR is highly unlikely to be merged.
But I will submit it anyway in case I am wrong.

This PR materially improves my quality of life because I regularly make use of both forms introduced by this PR during my interaction with Exercism, and have for many months.
However, I think it is unlikely to be merged because my feeling is that with the increased number of options for download (exercism download allows --uuid and --team compared to exercism fetch which only had exercise slug and track), it is desirable to be more explicit rather than implicit as this PR does. This PR makes too many implicit assumptions that are correct for one person's use cases, but are not necessarily correct for any other person's.

You need not feel guilt for closing this PR; it will not harm my workflow (because I will simply run it on my copy of the cli).

Original commit message below:


If I'm in the exercism/c directory and invoke:

exercism download --exercise hello-world

I would like --track c to be inferred.

If I'm in the exercism/c/hello-world directory and invoke without
arguments:

exercism download

I would like both --track c and --exercise hello-world to be
inferred.

@petertseng petertseng force-pushed the infercwd branch 2 times, most recently from b50dbad to 6a223b8 Compare September 15, 2019 06:51
@kytrinyx
Copy link
Member

I'm ok with using inference as long as the context is explicit. If the context cannot be guessed, then I'll want to provide an error message.

I will review the changes in the next few days (sorry it's taken so long to get to it)

@petertseng
Copy link
Member Author

petertseng commented Oct 21, 2019

Let me just pre-empt myself a bit here. So I realised I need to exclude users and teams from being considered track names. Just like https://github.com/exercism/cli/blob/master/workspace/workspace.go#L44-L60 does. So I should probably add a test for those special dirs too.

This is part of what makes this PR so difficult to craft and (I am sure) review - the download command has at least three different modes of operation (download mine, download someone else's, download a team's), and I am adding functionality to just the first modes and until just now was completely unaware of the other two. I need to make sure I do not stomp on the other modes.

@petertseng petertseng force-pushed the infercwd branch 2 times, most recently from c9ed045 to 65ac89b Compare October 22, 2019 06:44
@petertseng
Copy link
Member Author

I had to make some significant changes to make it not do the wrong thing on users and teams.

Main problem I ran into was that for users/whatever-user/whatever-track/whatever-slug, the previous code would set the slug to whatever-user, even if I made it not set track to users. To fix this problem, I had to have the inferring-the-slug part also check not only the second path component but also the first.

@@ -162,6 +162,19 @@ func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
d.apibaseurl = usrCfg.GetString("apibaseurl")
d.workspace = usrCfg.GetString("workspace")

if d.uuid == "" {
if d.slug == "" {
if _, slug, ok := trackAndSlugFromCwd(d.workspace); ok && slug != "" {
Copy link
Member Author

@petertseng petertseng Oct 25, 2019

Choose a reason for hiding this comment

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

oh, the != "" check is, strictly speaking, unnecessary. If we have gotten to this point, then d.slug is already "" and setting it from "" to "" does nothing.

@@ -349,6 +362,43 @@ func (sf solutionFile) relativePath() string {
return filepath.FromSlash(file)
}

func trackAndSlugFromCwd(workspace string) (string, string, bool) {
Copy link
Member Author

Choose a reason for hiding this comment

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

surely, it would be possible to call this flagsFromCwd and have it automatically detect the team if inside a teams directory (from CWD) and the UUID if inside users (but this requires reading a file in order to get the UUID). Since I don't use either of these pieces of functionality, and the latter needs more thought, I would not like to take on such a task in this PR.

@petertseng petertseng force-pushed the infercwd branch 3 times, most recently from 485a3bf to a3a4487 Compare October 26, 2019 04:54
If I'm in the `exercism/c` directory and invoke:

    exercism download --exercise hello-world

I would like `--track c` to be inferred.

If I'm in the `exercism/c/hello-world` directory and invoke without
arguments:

    exercism download

I would like both `--track c` and `--exercise hello-world` to be
inferred.
Base automatically changed from master to main January 28, 2021 22:32
@ErikSchierboom
Copy link
Member

If I'm in the exercism/c directory and invoke:

exercism download --exercise hello-world

I would like --track c to be inferred.

👍 I quite like this. It would be really useful.

If I'm in the exercism/c/hello-world directory and invoke without
arguments:

exercism download

I would like both --track c and --exercise hello-world to be
inferred.

I'm not certain how useful this would be. I'd be more than happy to try and get this PR merged with just the first option.

@petertseng are you still interested in working on this PR? If not, no worries.

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.

3 participants