質問

I have the following situation:

import sys
from cmd2 import Cmd, make_option, options

class DemoApp(Cmd):
    """Simple command processor example."""

    @options([make_option('-n', '--name', action="store", help="your name"),
         ])
    def do_hello(self, command, opts):
        if opts.name:
            sys.stdout.write('Hello %s\n' % opts.name)
        else:
            sys.stdout.write('Hello Nobody\n')

if __name__ == '__main__':
    DemoApp().cmdloop() 

I want to pass a string with spaces as paramater for option -n. (while in the cmd2 promt)

example:

->hello -n 'My awesome name'

when I do that it is printed:

Hello 'My

the same also with double quotes

so it does not accept spaces there. Does anybody know how to do that?

役に立ちましたか?

解決

I figured out was it happening. I submitted a bug in : https://bitbucket.org/catherinedevlin/cmd2/issues?status=new&status=open

plus a patch that fixes the bug. If someone has the same issue you can use the patch if the maintainer does not update the code.

他のヒント

Version 0.7 of cmd2 has a fix for this issue. cmd2 now properly treats quoted arguments as a single argument, regardless of the presence of spaces within the quotes. You can install the latest version of cmd2 from PyPI with:

pip install -U cmd2
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top