Make inputs required (show help if not provided)#329
Conversation
| ```ignore | ||
| USAGE: | ||
| lychee [FLAGS] [OPTIONS] [--] [inputs]... | ||
| lychee [FLAGS] [OPTIONS] <inputs>... |
There was a problem hiding this comment.
Probably keep that [--]? I mean the hint is in mentioned below as well, but I remember I've overseen it in one place and required a few attempts before I figured out that -- was possible and required to have the last arguments count as inputs instead of option arguments 😄.
There was a problem hiding this comment.
Yeah I noticed that as well, but I ran some tests and couldn't find a case where the -- was still required. Structopt seems to remove the [--] from the usage section if it's not strictly necessary. 🤷♀️
Any way you can reproduce the old failing behavior with this branch? If so, we need to find out how to enforce the old syntax in the usage info (which is auto-generated and tested by a doc-test, so we can't just manually edit it). If not, we might want to remove the hint below. (Which I count as a win. 😄)
BTW this also still works, so it's not a breaking change unless we can find another issue:
lychee -- README.md
There was a problem hiding this comment.
Ah, even when using an option with multiple value support, like:
lychee --exclude 'this' 'that' 'next' README.mdHow does it know where the excludes end and where the inputs start?
There was a problem hiding this comment.
Yeah that doesn't work:
lychee --exclude this that next README.md
error: The following required arguments were not provided:
<inputs>...There was a problem hiding this comment.
This is the code for the [--] part:
https://github.com/clap-rs/clap/blob/88dec14775fc94170b79c38d88da5385c5b9b6e8/src/output/usage.rs#L84-L106
There was a problem hiding this comment.
So the easiest thing was to add last = true. No idea if that's how it's meant to be done. 😆
There was a problem hiding this comment.
So now the last input argument is automatically used as input in such case (or is it that inputs need to be the last arguments now)? Still good to keep the hint visible as also this may happen:
lychee --exclude 'this' 'that' index.html README.mdThere was a problem hiding this comment.
I understood it as "inputs need to be the last arguments now".
There was a problem hiding this comment.
Okay, then I don't understand how last = true helps in this context 😄. However, I think its okay when -- is required in some cases. Better to force users to be explicit than being implicit and guess wrong about what was meant. The only other alternative I see would be to allow only single options values, and e.g. have multiple excludes/schemes/etc separated by ,. But especially with excludes which may contain literal , themselves it is a bit difficult and would be a breaking change.
... although also multiple excludes (same with includes) can be merged into a single regex (we do it like that):
lychee --exclude '^https://(example.org|another.com|localhost)'
and multiple schemes can easily be comma-separated. Only with headers it would be complicated to achieve.
Very interesting that the clap-rs crate adds [--] when there are options which allow multiple values (the code look quite clear about that) and even that there are several which do, it didn't add it in our case?
There was a problem hiding this comment.
BTW this also still works, so it's not a breaking change unless we can find another issue:
Very interesting that the clap-rs crate adds [--] when there are options which allow multiple values (the code look quite clear about that) and even that there are several which do, it didn't add it in our case?
It's a convention that -- signals the end of CLI options/flags. Anything after that is parsed as positional arguments.
But it's still helpful to remind users of --. Suppose a filename starts with -, one way to handle it correctly is to use lychee -- -FILENAME.
Also, although there's no need to manually make input as the last argument (actually it's the first positional argument). it's easier for users to learn the syntax in case they don't know the -- convention.
|
This doesn't work yet. The above case worked before (without |
removing See https://docs.rs/clap/2.33.3/clap/struct.Arg.html#method.last
|
Ah that was the part we didn't expect 👍. Then I wonder why |
|
|
Now Checking code: https://github.com/clap-rs/clap/blob/88dec14775fc94170b79c38d88da5385c5b9b6e8/src/output/usage.rs#L84-L106 I think the problem is
IMHO # This fails not despite but because of "required = true" without "--":
lychee --exclude 'this' 'that' 'next' README.md
# And even with "last = true" it fails to do what you want as long as multiple ARGS are allowed:
lychee --exclude 'this' 'that' index.html README.mdSo I'd re-add |
|
I agree with your conclusion. The current implementation in clap is not technically incorrect however, so they might decline a change. The This would be But probably we should just ask them about their opinion. I don't consider this a blocker, though. |
|
Isn't it an option to add it manually for now? Anyway not a blocker. I just remember that I exactly got stuck, even that I knew/used the trick before and even that it was in the usage string 😄: #113 |
|
Yeah we could overwrite the description, but then we'd run risk of forgetting to keep it up-to-date in the future. And incorrect information is worse than no information, so I'd like fix that upstream if possible. |
Fixes #327
@fauust fyi