-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Add a concept of 'tail' arguments #11757
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
Conversation
9470533
to
1fc5c83
Compare
1fc5c83
to
1860379
Compare
👍 |
throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode)); | ||
} elseif ($mode & self::IS_TAIL && !($mode & self::IS_ARRAY)) { |
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.
IMO, this is bad DX. Adding the IS_TAIL
flag should add IS_ARRAY
automatically (by using 12 as value for the constant)
the issue with for instance, if you just ran a command and want to see the same in verbose mode, you can move up in your history to get the command again, and then simply add |
Given these limitations, I think it might be OK to add it to cover the specific use case described here, but the documentation should clearly discourage using it in the general case |
@@ -45,8 +46,10 @@ public function __construct($name, $mode = null, $description = '', $default = n | |||
{ | |||
if (null === $mode) { | |||
$mode = self::OPTIONAL; | |||
} elseif (!is_int($mode) || $mode > 7 || $mode < 1) { | |||
} elseif (!is_int($mode) || $mode > 15 || $mode < 1) { |
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.
@fabpot should we remove the upper bound check ? It makes it impossible to write forward-compatible commands (for instance a command trying to pass 12
as value to have IS_ARRAY | IS_TAIL
for people using 2.6+ allowing to omit the --
, but still being compatible with older Console versions to support the LTS (users would simply have to pass --
when wanting to pass an option).
If we decide to make the forward compatibility possible, we should probably do the change in 2.3 though (otherwise it would only allow it for 2.6+ for the next time we add a flag)
Do we still need this feature now that #11431 has been merged and released in 3.0? |
The user experience is different, here I was trying to achieve this without the explicit |
This PR introduces the concept of a "tail argument". It is essentially an extension of the concept of
InputArgument::IS_ARRAY
that allows the last argument in the command line to unconditionally capture all the remaining arguments, whether they look like options or not.The use case targeted here is the one of command lines that chains or wrap other command lines. It makes possible to implement those without forcing the user to use the
--
separator to explicitly separate the options of the wrapper with the options of the wrapped command (at least when they are non-overlapping).