我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pip.commands.get_summaries()。
def create_main_parser(): parser_kw = { 'usage': '\n%prog <command> [options]', 'add_help_option': False, 'formatter': UpdatingDefaultsHelpFormatter(), 'name': 'global', 'prog': get_prog(), } parser = ConfigOptionParser(**parser_kw) parser.disable_interspersed_args() pip_pkg_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) parser.version = 'pip %s from %s (python %s)' % ( __version__, pip_pkg_dir, sys.version[:3]) # add the general options gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser) parser.add_option_group(gen_opts) parser.main = True # so the help formatter knows # create command listing for description command_summaries = get_summaries() description = [''] + ['%-27s %s' % (i, j) for i, j in command_summaries] parser.description = '\n'.join(description) return parser
def parseopts(args): parser = create_main_parser() parser.main = True # so the help formatter knows # create command listing command_summaries = get_summaries() description = [''] + ['%-27s %s' % (i, j) for i, j in command_summaries] parser.description = '\n'.join(description) options, args = parser.parse_args(args) if options.version: sys.stdout.write(parser.version) sys.stdout.write(os.linesep) sys.exit() # pip || pip help || pip --help -> print_help() if not args or (args[0] == 'help' and len(args) == 1): parser.print_help() sys.exit() if not args: msg = ('You must give a command ' '(use "pip --help" to see a list of commands)') raise CommandError(msg) command = args[0].lower() if command not in commands: guess = get_similar_commands(command) msg = ['unknown command "%s"' % command] if guess: msg.append('maybe you meant "%s"' % guess) raise CommandError(' - '.join(msg)) return command, options, args, parser