本文整理汇总了Python中django.core.management.base.CommandParser.add_option方法的典型用法代码示例。如果您正苦于以下问题:Python CommandParser.add_option方法的具体用法?Python CommandParser.add_option怎么用?Python CommandParser.add_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.management.base.CommandParser
的用法示例。
在下文中一共展示了CommandParser.add_option方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from django.core.management.base import CommandParser [as 别名]
# 或者: from django.core.management.base.CommandParser import add_option [as 别名]
def execute(self, argv=None, stdout=None, stderr=None):
if argv is None:
argv = sys.argv
if stdout is None:
stdout = sys.stdout
if stderr is None:
stderr = sys.stderr
if django.VERSION >= (1, 8):
from django.core.management.base import CommandParser
parser = CommandParser(None,
usage="%(prog)s subcommand [options] [args]",
add_help=False)
parser.add_argument('--version', action='store_true', help="show program's version number and exit")
parser.add_argument('-h', '--help', action='store_true', help="show this help message and exit")
try:
options, argv = parser.parse_known_args(argv)
except:
pass # Ignore any option errors at this point.
else:
from django.core.management import LaxOptionParser
parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
option_list=(),
add_help_option=False)
parser.add_option('--version', action='store_true', help="show program's version number and exit")
parser.add_option('-h', '--help', action='store_true', help="show this help message and exit")
try:
options, argv = parser.parse_args(argv)
except:
pass # Ignore any option errors at this point.
if len(argv) > 1:
subcommand = argv[1]
else:
subcommand = 'help' # Display help if no arguments were given.
if options.help:
if subcommand == 'help':
if hasattr(parser, 'print_lax_help'):
parser.print_lax_help()
else:
parser.print_help(stdout)
stdout.write(self.main_help_text() + '\n')
else:
command = self.fetch_command(subcommand)
if command is not None:
command.print_help(self.prog_name, subcommand, file=stdout)
else:
stdout.write(self.unknown_command_text(subcommand) + '\n')
elif subcommand == 'version' or options.version:
stdout.write(wirecloud.platform.__version__ + '\n')
elif subcommand == 'help':
if len(argv) <= 2:
if hasattr(parser, 'print_lax_help'):
parser.print_lax_help()
else:
parser.print_help(stdout)
stdout.write(self.main_help_text() + '\n')
elif argv[2] == '--commands':
stdout.write(self.main_help_text(commands_only=True) + '\n')
else:
command = self.fetch_command(argv[2])
if command is not None:
command.print_help(self.prog_name, argv[2], file=stdout)
else:
stdout.write(self.unknown_command_text(argv[2]) + '\n')
else:
command = self.fetch_command(subcommand)
if command is not None:
command.run_from_argv(argv, stdout=stdout, stderr=stderr)
else:
stdout.write(self.unknown_command_text(subcommand) + '\n')