Infinidat / infi.docopt_completion

BSD 3-Clause "New" or "Revised" License
109 stars 9 forks source link

file completion not working #12

Closed kindlychung closed 8 years ago

kindlychung commented 8 years ago

Here is the result of smail --help:

Usage:
  smail send    (-t <to>)... [-s <subj>] [-b <body>] [(-a <attach>)...] [(-l <label>)...]
  smail send    -m <msgfile>
  smail draft   (-t <to>)... [-s <subj>] [-b <body>] [(-a <attach>)...] [(-l <label>)...]
  smail draft   -m <msgfile>
  smail insert  (-t <to>)... [-s <subj>] [-b <body>] [(-a <attach>)...] [(-l <label>)...]
  smail insert  -m <msgfile>

Options:
  -t Recipient address.
  -s Email subject. Default to "No subject".
  -b Email body. Default to empty string.
  -a Attachemnt.
  -l Label. Default to "smail".
  -m Use a message file and specify the options in it.

After docopt-completion smail, the commands are autocompleted fine, but if I type smail send -m /tmp/tes then tab, the filename doesn't get autocompleted.

wiggin15 commented 8 years ago

You should add more spaces in the "Options" section, between the option and the descriptions - like this:

Usage:
  smail send    (-t <to>)... [-s <subj>] [-b <body>] [(-a <attach>)...] [(-l <label>)...]
  smail send    -m <msgfile>
  smail draft   (-t <to>)... [-s <subj>] [-b <body>] [(-a <attach>)...] [(-l <label>)...]
  smail draft   -m <msgfile>
  smail insert  (-t <to>)... [-s <subj>] [-b <body>] [(-a <attach>)...] [(-l <label>)...]
  smail insert  -m <msgfile>

Options:
  -t    Recipient address.
  -s    Email subject. Default to "No subject".
  -b    Email body. Default to empty string.
  -a    Attachemnt.
  -l    Label. Default to "smail".
  -m    Use a message file and specify the options in it.

docopt requires at least two spaces between the options and their description, otherwise it parses the options wrong. With one space instead of two or more, you'll also get different behavior from docopt - e.g. you will not have <msgfile> in the returned arguments, and you can pass things like "smail send -m=1" and docopt will accept this.

Let me know how this works out.

kindlychung commented 8 years ago

Now it's working. I have one objection though, when completing file path, it would make more sense not to put a trailing space. For example: /tm tab should produce /tmp instead of /tmp, because the user is likely to go deeper in the path, and it's annoying that you have to hit backspace all the time.