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

Support for docker like arguments termination #360

Closed
omribahumi opened this issue Jun 14, 2015 · 10 comments
Closed

Support for docker like arguments termination #360

omribahumi opened this issue Jun 14, 2015 · 10 comments

Comments

@omribahumi
Copy link

Is it possible to replace the -- termination with something else?

I would like to wrap the docker run command with my own, preserving the docker behaviour.

The docker run command arguments are:

Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

The IMAGE parameter terminates the command line arguments (and is retrievable from the command line parser). I would like to do the same with click. Essentially, this means that the -- termination would be configurable and retrievable.

The implementation I had in mind is specifying an extra keyword argument to the @click.argument() decorator (something like terminating=True)

Any thoughts?

@untitaker
Copy link
Contributor

I'd say that it's not a good idea to wrap existing CLIs with Click, because click has many opinions on e.g. helptext formatting that allow you to create nice CLIs very quickly, but not exactly replicate existing ones.

The IMAGE parameter terminates the command line arguments (and is retrievable from the command line parser).

That's wrong, it seems to terminate the options. You can do the same with Click:

import click

@click.group()
def cli():
    pass

@cli.command()
@click.argument('image')
@click.argument('command', nargs=-1)
def run():
    '''
    Adasdasdas
    '''
    pass

cli()

In this case the command list specifies command and args to execute in the docker image -- this is not a difference in usage, but only in the helptext.

@omribahumi
Copy link
Author

@untitaker that's not what I want. For example:

#!/usr/bin/env python
import click

@click.group()
def cli():
    pass

@cli.command()
@click.argument('image')
@click.argument('command', nargs=-1)
def run(image, command):
    print 'image', image
    print 'command', command

cli()

Then, if I do something like:

$ ./clicktest.py run image 'a b' c d
image image
command (u'a b', u'c', u'd')

It works ok. But when I do something like:

$ ./clicktest.py run image 'a b' c d --arg
Usage: clicktest.py run [OPTIONS] IMAGE [COMMAND]...

Error: no such option: --arg

The behavior I want is "IMAGE" to terminate the arguments so I'll be able to read

('a b', 'c', 'd', '--arg')

@untitaker
Copy link
Contributor

I see, but again, it's not arguments, you mean options.

@omribahumi
Copy link
Author

@untitaker I mentioned wanting to imply -- :)

@omribahumi
Copy link
Author

@untitaker could you give me a lead on how to implement this? I'll do it and create a pull request

@mitsuhiko
Copy link
Contributor

You should be able to implement this by making an image subcommand and then doing this: http://click.pocoo.org/4/advanced/#forwarding-unknown-options

@omribahumi
Copy link
Author

@mitsuhiko image is not static

@untitaker
Copy link
Contributor

click.UNPROCESSED doesn't seem to be enough, Click still intercepts anything that starts with --.

@untitaker untitaker reopened this Jul 20, 2015
@mitsuhiko
Copy link
Contributor

Removing the parsing for -- might be nearly impossible. I just looked through this a bit and it's just way too far in the wrong part of the stack to make this not handled.

@jcrotts
Copy link
Contributor

jcrotts commented May 15, 2018

Closing this it seems like it would be really difficult to implement per mitsuhiko, and the use case looks somewhat limited.

@jcrotts jcrotts closed this as completed May 15, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants