incorrect parsing
See original GitHub issuehere is a script I am trying to get working
#!/usr/bin/env python
"""Send emails.
Usage:
sendmail.py -s <subject> --to <to-addr> [ --from <from-addr> ] [ --cc <cc-addr> ] [ --bcc <bcc-addr> ]
sendmail.py (-h | --help)
Options:
-h show this help
"""
from docopt import docopt
from sys import argv, stdin
if __name__ == '__main__':
arguments = docopt(__doc__)
if arguments['--from'] == False:
fromaddr = "barney@example.com"
else:
fromaddr = arguments['<from-addr>']
print("you'll need to edit the script to add the password for this email.")
exit(1)
body = stdin.read()
subject = arguments['<subject>']
toaddrs = arguments['<to-addr>']
print(arguments)
When I invoke the script like so:
echo foobar | ./sendmail.py -s blah --to blah@blah.blah --cc other@some.email --bcc hidden@some.email
I get this output:
{'--bcc': True, '--cc': True, '--from': False, '--help': False, '--to': True, '-h': [], '-s': True, '<bcc-addr>': None, '<cc-addr>': 'hidden@some.email', '<from-addr>': 'other@some.email', '<subject>': 'blah', '<to-addr>': 'blah@blah.blah', 'Options:': False, 'help': False, 'this': False}
But that is plainly incorrect: from-addr was never specified, so it should be “barney@example.com”, while bcc-addr should be what cc-addr is, and cc-addr should be what from-addr is. Some kind of weird argument shifting is happening, and it seems like the argument keys are being completely ignored.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top GitHub Comments
It seems that if
<argument>
is mentioned in the Options sectionAnd you call it with
script.py -o my_arg
, thendocopt
will return:While if you do not mention
<argument>
in the Options section it will return:You need to include all the options in the Options section; also need a blank line between Usage and Options. Try: