-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix regression in handling flag-values starting with hyphen #1135
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 still not quite correct if you wanted to do something like:
Where it would still re-order things. The least-ugly way I can think of solving this is that we change
nextIndexMayContainValue
to make use ofTakesValue()
(with some interface casting) and removing this "skip reordering flags that start with-
" logic if it doesn't break anything.I also hasten to point out that
urfave/cli
has actually had this behaviour for a very long time and we (speaking collectively in the containers community) have misunderstood howurfave/cli
handles this case. I discussed this in #1152 (which I've marked as a duplicate of this) and I've had to work around this in umoci (see opencontainers/umoci#328 for how I ended up hotfixing this -- you just disable argument reordering). Since we want to avoid breaking other users ofurfave/cli
we might have to migrate runc, umoci, and containerd away fromurfave/cli
(maybe tospf13/cobra
which is what Docker uses)...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.
A possible patch to do the above might look like the following. This change does pass all of the existing tests...
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.
@cyphar I see you commented on the first commit; did you check with the second commit as well?
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 was looking at the requested changes to preserve some of the existing behaviour)
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.
No, this was just talking about the behaviour of the first change (and not the fun
--
semantics that you quizzed everyone on in May). I /think/ that it should be fairly straight-forward (move the--
check after the "is this an option-value check" as in your current patch) but I agree with both of you that that particular change looks quite scary.I think the
--opt -a
case is far more clear-cut.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.
So, in your example case (
runc run --bundle --some-real-runc-flag
) both--bundle
and--some-real-runc-flag
are "known" flags torunc
, but the second one should be treated as value for--bundle
(so--bundle="--some-real-runc-flag"
) or as flag? In the former case, wouldn't it have to be used asrunc run --bundle -- --some-real-runc-flag
? 🤔)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.
The former (
--some-real-runc-flag
treated as a avalue for--bundle
). The motivating use-case is (aside from POSIX-correctness and compatibility withgetopt(3)
) similar to--
:(Well, for umoci it's more like
umoci config --image foo:bar --config.cmd sh --config.cmd -c
but that's a slightly more complicated example. But the root cause is the same as your original--memory-limit -1
issue.)Should mean that
--foo
is a value for--bundle
regardless of whether--foo
is a known command-line flag. Currently (and with your patches),urfave/cli
will not reorder--bundle --foo
(where--foo
is not a valid flag forrunc
) but it will reorder the flags if you do--bundle --systemd-cgroup
(where--systemd-cgroup
is a supported flag forrunc
). Even more strangely,--bundle=--systemd-cgroup
works without issue because the arguments don't get reordered.The patch I posted above should make it so that
--bundle=--foo
acts exactly like--bundle --foo
regardless of whether--foo
is a validrunc
flag.I disagree (especially if we take the interpretation that
--
should be an option-value in that case). If you use getopt:But also it's the obvious behaviour if you just inject
=
s: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.
@thaJeztah PTAL?
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.
ping @thaJeztah 🙏