-
-
Notifications
You must be signed in to change notification settings - Fork 361
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
base: main
Are you sure you want to change the base?
Conversation
b50dbad
to
6a223b8
Compare
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) |
Let me just pre-empt myself a bit here. So I realised I need to exclude This is part of what makes this PR so difficult to craft and (I am sure) review - the |
c9ed045
to
65ac89b
Compare
I had to make some significant changes to make it not do the wrong thing on Main problem I ran into was that for |
@@ -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 != "" { |
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.
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) { |
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.
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.
485a3bf
to
a3a4487
Compare
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.
👍 I quite like this. It would be really useful.
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. |
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 toexercism 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:I would like
--track c
to be inferred.If I'm in the
exercism/c/hello-world
directory and invoke withoutarguments:
I would like both
--track c
and--exercise hello-world
to beinferred.