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

Allow input to be a positional argument #375

Closed
quietvoid opened this issue Apr 12, 2020 · 3 comments
Closed

Allow input to be a positional argument #375

quietvoid opened this issue Apr 12, 2020 · 3 comments

Comments

@quietvoid
Copy link

Hi, thank you for this tool.
I think forcing --input PATH is a little too verbose for most use cases.
Most other tools out there simply allow a named argument as well as a long option for it.

Currently, this fails:

$ imdl torrent show myfiles.torrent

error: Found argument 'myfiles.torrent' which wasn't expected, or isn't valid in this context
USAGE: imdl torrent show --input <PATH>

structopt should support using name = "PATH", however I don't know how it behaves with subcommands.

@murlakatamenka
Copy link

murlakatamenka commented Apr 12, 2020

I pretty much agree that some simplification can be beneficial.

Actually what you ask for is to make named arguments positional ones (see structopt docs).

Subcommands in structopt aren't special, they are usual struct/enum's included into main one. Or even enum variants, as in git example.


Relevant cases:

  • creating torrents: imdl create -o <output> <INPUT_FILE_OR_DIR>...
  • showing torrents: imdl show <TORRENT>...
  • completions: imdl completions <shell_name>
    This is what almost any rust'y CLI utility does, including rustup itself!

@quietvoid quietvoid changed the title Allow input to be a named argument Allow input to be a named positional argument Apr 12, 2020
@quietvoid quietvoid changed the title Allow input to be a named positional argument Allow input to be a positional argument Apr 12, 2020
@casey
Copy link
Owner

casey commented Apr 13, 2020

I think this is totally reasonable. I'd like to figure out a way to do this without changing the existing usage, since I think it can be easier to remember what's what using a short or long flag.

This isn't supported directly by clap, the argument parsing library that intermodal uses, but I opened an issue to request an easy way to do this: clap-rs/clap#1820

For now, I think this can be accomplished by using arg groups, or making the positional option conflict with the flag option.

casey added a commit that referenced this issue Apr 22, 2020
Allow taking the `--input` argument to `imdl torrent create` as a
positional argument, so the following now works:

    imdl torrent create foo

Taking input by flag `--input` still works.

type: changed
fixes:
- #375
casey added a commit that referenced this issue Apr 22, 2020
Input can now be passed to `imdl torrent verify` without a flag:

  imdl torrent verify foo.torrent

Passing input by flag continues to work.

type: changed
fixes:
- #375
casey added a commit that referenced this issue Apr 22, 2020
The shell can now be passed to `imdl completions` without a flag:

  imdl completions bash

Passing the shell by flag continues to work.

type: changed
fixes:
- #375
casey added a commit that referenced this issue Apr 22, 2020
Input can now be passed to `imdl torrent show` without a flag:

  imdl torrent show foo.torrent

Passing input by flag continues to work.

type: changed
fixes:
- #375
casey added a commit that referenced this issue Apr 22, 2020
Input can now be passed to `imdl torrent show` without a flag:

  imdl torrent show foo.torrent

Passing input by flag continues to work.

type: changed
fixes:
- #375
@casey
Copy link
Owner

casey commented Apr 23, 2020

This is done! The following commands can take their main input as a positional argument:

imdl torrent create

imdl torrent link

imdl torrent show

imdl torrent verify

imld completions

The old flags still work, and will continue to work going forward, so there's no breakage with existing usage.

I just released v0.1.7, which includes this change.

@casey casey closed this as completed Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants