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

Treat all flags which followd behind the last arguments as normal arg… #515

Closed
wants to merge 1 commit into from
Closed

Treat all flags which followd behind the last arguments as normal arg… #515

wants to merge 1 commit into from

Conversation

keloyang
Copy link

@keloyang keloyang commented Aug 30, 2016

If SkipFlagParsing is not considered,cli treat all words which start by '-' as flag, so when the subcommand has a argument which start by '-', it also will treated as cli' flag, not a argument for subcommand.
e.g.

root@ubuntu:~/# runc exec test ls -la    
Incorrect Usage.

I think cli should treat all flags which followd behind the last arguments as normal arguments,just like this:

root@ubuntu:~/# runc exec test ls -la            
total 44
drwxr-xr-x   12 root     root          4096 Aug 30 06:37 .
drwxr-xr-x   12 root     root          4096 Aug 30 06:37 ..
-rwxr-xr-x    1 root     root             0 Aug 30 02:23 .dockerenv
-rwxr-xr-x    1 root     root             0 Aug 30 02:23 .dockerinit
...

opencontainers/runc#752 for details.
Signed-off-by: Shukui Yang yangshukui@huawei.com

@keloyang
Copy link
Author

keloyang commented Aug 30, 2016

ping @jszwedko @bryanl @dam5s @gravis @rmg

@gravis
Copy link
Member

gravis commented Sep 1, 2016

LGTM
If no one else is taking this, I'll merge the PR in 10 days.

@jszwedko
Copy link
Contributor

jszwedko commented Sep 3, 2016

The usual "unix-y" way to handle this (which this library supports thanks to stdlib flag support) is to use -- to specify that all following arguments should be parsed as arguments rather than flags.

I can see the argument you are making for ... exec-like commands though. Would the support for SkipFlagParsing support your use case? Or would the exec subcommand also have flags of its own in addition to the freeform command?

@keloyang
Copy link
Author

keloyang commented Sep 5, 2016

yes, add -- is ok, but use "runc exec -- test ls -la" instead "runc exec test ls -la", some people think it might be a bug.
SkipFlagParsing also don't work for me,
e.g.

runc exec --cwd /  test ls -la 

it will skip -la, but it also skip --cwd.
On the other hand, this pr will change the action for the last argument, So I modify it to add a SkipLastFlagParsing to keep backward compatibility.
ping @jszwedko - -

…uments

Signed-off-by: Shukui Yang <yangshukui@huawei.com>
@jszwedko
Copy link
Contributor

jszwedko commented Sep 9, 2016

@keloyang gotcha, so the subcommand also has flags.

The behavior you describe is actually the default behavior of the underlying flag library that we use, but we do some argument rearranging (that I removed in the unreleased v2 branch in #398 because it only worked under very specific circumstances and supporting complete reordering would require much more effort).

I can imagine a future where cli supports flags and arguments being intermixed (a need expressed in #427), but because this is not currently supported and wouldn't be in this particular version (nor probably in v2), I'm OK with including this. Given it will be the default behavior in v2, I'm almost inclined to call the option NoArgumentReorder, document that it is backported behavior, and make it closer to the behavior in v2.

Let me know what you think about this and I can backport it.

Thanks for bringing this up! (and apologies for stepping on your toes @gravis 😄 -- this issue just reminded me of the work I'd done in #398 around removing reordering).

@keloyang
Copy link
Author

keloyang commented Sep 9, 2016

@jszwedko thank for your reply, It's nice to backport #398 and it can resolve the problem above.

@meatballhat
Copy link
Member

@gravis you've still got this? 😸

@jszwedko
Copy link
Contributor

I was planning on working on the backport of #398 today, but let me know if anyone is actively working on this!

@jszwedko jszwedko self-assigned this Sep 11, 2016
jszwedko added a commit that referenced this pull request Sep 11, 2016
In the unreleased version 2, the argument reordering has been removed
(in f585ec7) since it only worked if
all of the arguments appeared before all of the flags, but not if they
were intermixed which was of limited utility and caused some confusion.
This commit allows enabling of this future behavior via SkipArgReorder.

Ideally we'd support complete intermingling of flags and arguments, but
this is unlikely to happen until we switch flag parsers.

Fixes #515
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.

4 participants