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

parse_args fails with docopt 'command' usage : AttributeError: 'Command' object has no attribute 'type' #16

Open
muellerk22 opened this issue Feb 8, 2022 · 1 comment

Comments

@muellerk22
Copy link

I have a basic DocOps string that fails when a command is added.

Here is the script

#!/usr/bin/env python
"""

Usage:
    ops.py app
    ops.py (-h | --help)
    ops.py (-v | --version)

Options:
    app                call the app
    -v --version       Version Information
    -h --help          Usage help.

"""
import shtab
from argopt import argopt
from docopt import docopt

if __name__ == "__main__":

    arguments = docopt(__doc__)
    print(arguments)

    parser = argopt(__doc__)
    shtab.add_argument_to(parser, ["-s", "--print-completion"])  # magic!

    args = parser.parse_args()

    print("Profit!")

Make it executable chmod u+x ops.py

Then execute /ops.py --version

The results is

% ./ops.py  --version
{'--help': False,
 '--version': True,
 'app': False}
dropped:Option('-h', '--help', 0, False, <class 'bool'>, None)
dropped:Option('-v', '--version', 0, False, <class 'bool'>, None)
Traceback (most recent call last):
  File "/Users/kevinmueller/projects/shtab-test/./ops.py", line 24, in <module>
    parser = argopt(__doc__)
  File "/Users/kevinmueller/.pyenv/versions/3.9.7/lib/python3.9/site-packages/argopt/_argopt.py", line 175, in argopt
    args, opts = docopt_parser(doc,
  File "/Users/kevinmueller/.pyenv/versions/3.9.7/lib/python3.9/site-packages/argopt/_argopt.py", line 89, in docopt_parser
    str_pattern = str(pattern)
  File "/Users/kevinmueller/.pyenv/versions/3.9.7/lib/python3.9/site-packages/argopt/_docopt.py", line 164, in __repr__
    ', '.join(repr(a) for a in self.children))
  File "/Users/kevinmueller/.pyenv/versions/3.9.7/lib/python3.9/site-packages/argopt/_docopt.py", line 164, in <genexpr>
    ', '.join(repr(a) for a in self.children))
  File "/Users/kevinmueller/.pyenv/versions/3.9.7/lib/python3.9/site-packages/argopt/_docopt.py", line 164, in __repr__
    ', '.join(repr(a) for a in self.children))
  File "/Users/kevinmueller/.pyenv/versions/3.9.7/lib/python3.9/site-packages/argopt/_docopt.py", line 164, in <genexpr>
    ', '.join(repr(a) for a in self.children))
  File "/Users/kevinmueller/.pyenv/versions/3.9.7/lib/python3.9/site-packages/argopt/_docopt.py", line 164, in __repr__
    ', '.join(repr(a) for a in self.children))
  File "/Users/kevinmueller/.pyenv/versions/3.9.7/lib/python3.9/site-packages/argopt/_docopt.py", line 164, in <genexpr>
    ', '.join(repr(a) for a in self.children))
  File "/Users/kevinmueller/.pyenv/versions/3.9.7/lib/python3.9/site-packages/argopt/_docopt.py", line 132, in __repr__
    self.value, self.type)
AttributeError: 'Command' object has no attribute 'type'

You can see I'm parsing the doc with docopt and I'm able to print out the options. I may be assuming this is a proper Doc string with this working.

I'm parsing with argopt so I can add tag completion in a zsh environment but I am unable to get past this point.

Requirements.txt

argopt==0.7.0
shtab==1.5.3
docopt==0.6.2

python --version

Python 3.9.7

Thank you in advance for your time.

@muellerk22
Copy link
Author

I see this is a repeat of issue #3. #3
Sorry about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant