简体   繁体   English

cmd2命令行参数

[英]cmd2 command line arguments

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. 我想传递一个带有空格的字符串作为选项-n的参数。 (while in the cmd2 promt) (在cmd2 promt中)

example: 例:

->hello -n 'My awesome name' ->你好-n'我的名字'

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 我在以下位置提交了一个错误: 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的0.7版已解决此问题。 cmd2 now properly treats quoted arguments as a single argument, regardless of the presence of spaces within the quotes. cmd2现在可以正确地将带引号的参数视为单个参数,而不管引号中是否存在空格。 You can install the latest version of cmd2 from PyPI with: 您可以使用以下方法从PyPI安装最新版本的cmd2:

pip install -U cmd2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM