You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
however I need to use cleo because I'm creating a poetry plugin for PoeThePoet which allows users to pass unknown arguments to a task e.g.
poe test<any args passed here will be forwarded to pytest>
It looks like this is currently not supported though I'd be happy to be proven wrong on that.
I'm willing to do the leg work to add support for this, since the only alternatives for integrating with poetry are either to drop key features when used as a plugin or to monkey patch Cleo at runtime 😞.
Workaround
I've found the following workaround that seems to produce the desired result (for now) by monkey patching cleo:
defmonkey_patch_cleo(command: str):
"""Monkey patch cleo, e.g. while activating the poetry plugin"""importcleo.applicationcontinue_run=cleo.application.Application._rundef_run(self, io):
# Trick cleo to ignoring anything following the command from this plugin # by injecting a '--' token at the start of the list of command line tokenstokens=io.input._tokensiftokensandtokens[0] ==command:
# update tokens list in placetokens.insert(0, "--")
continue_run(self, io)
# Apply the patchcleo.application.Application._run=_runclassMyCommand(Command):
name="my-command"def__init__(self):
super().__init__()
self._ignore_validation_errors=True# Don't fail given unknown argumentsdefhandle(self):
args=self.io.input._tokens[:]
ifargs[0] =="--": # ignore the extra token introduced by the monkey patchargs=tokenized_input[1:]
...
Proposal
A better solution would involve being able to configure the Command to have freeform arguments, e.g.
Which carries over to resulting Definition object which in turn causes the ArgvInput instance to skip parsing of options. Parsing of positional arguments could still work the same I think.
The text was updated successfully, but these errors were encountered:
nat-n
changed the title
Any way to accept unknown arguments
Accept unknown arguments (for poetry plugin)
Dec 28, 2021
nat-n
changed the title
Accept unknown arguments (for poetry plugin)
Accept unknown options (for poetry plugin)
Dec 28, 2021
I require a way to make a cleo Command accept unknown options and arguments, and not inherit the application options.
The equivalent in argparse would be something like:
however I need to use cleo because I'm creating a poetry plugin for PoeThePoet which allows users to pass unknown arguments to a task e.g.
It looks like this is currently not supported though I'd be happy to be proven wrong on that.
I'm willing to do the leg work to add support for this, since the only alternatives for integrating with poetry are either to drop key features when used as a plugin or to monkey patch Cleo at runtime 😞.
Workaround
I've found the following workaround that seems to produce the desired result (for now) by monkey patching cleo:
Proposal
A better solution would involve being able to configure the Command to have freeform arguments, e.g.
Which carries over to resulting Definition object which in turn causes the ArgvInput instance to skip parsing of options. Parsing of positional arguments could still work the same I think.
The text was updated successfully, but these errors were encountered: