def parsecmdline(args=sys.argv): options = {} try: args = fancyopts.fancyopts(args, globalopts, options, True) except fancyopts.getopt.GetoptError, inst: raise Exception("error.CommandError(None, %r)" % inst)
def _checkshellalias(lui, ui, args): norepo = commands.norepo options = {} try: args = fancyopts.fancyopts(args, commands.globalopts, options) except fancyopts.getopt.GetoptError: return if not args: return cmdtable = commands.table.copy() addaliases(lui, cmdtable) cmd = args[0] try: aliases, entry = cmdutil.findcmd(cmd, cmdtable, lui.config("ui", "strict")) except (error.AmbiguousCommand, error.UnknownCommand): commands.norepo = norepo return cmd = aliases[0] fn = entry[0] if cmd and util.safehasattr(fn, 'shell'): d = lambda: fn(ui, *args[1:]) return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {}) commands.norepo = norepo
def _parse(ui, args): options = {} cmdoptions = {} try: args = fancyopts.fancyopts(args, commands.globalopts, options) except fancyopts.getopt.GetoptError, inst: raise error.CommandError(None, inst)
def _parse(ui, args): options = {} cmdoptions = {} try: args = fancyopts.fancyopts(args, commands.globalopts, options) except fancyopts.getopt.GetoptError as inst: raise error.CommandError(None, inst) if args: cmd, args = args[0], args[1:] aliases, entry = cmdutil.findcmd(cmd, commands.table, ui.configbool("ui", "strict")) cmd = aliases[0] args = aliasargs(entry[0], args) defaults = ui.config("defaults", cmd) if defaults: args = map(util.expandpath, shlex.split(defaults)) + args c = list(entry[1]) else: cmd = None c = [] # combine global options into local for o in commands.globalopts: c.append((o[0], o[1], options[o[1]], o[3])) try: args = fancyopts.fancyopts(args, c, cmdoptions, True) except fancyopts.getopt.GetoptError as inst: raise error.CommandError(cmd, inst) # separate global options back out for o in commands.globalopts: n = o[1] options[n] = cmdoptions[n] del cmdoptions[n] return (cmd, cmd and entry[0] or None, args, options, cmdoptions)
def _checkshellalias(lui, ui, args, precheck=True): """Return the function to run the shell alias, if it is required 'precheck' is whether this function is invoked before adding aliases or not. """ options = {} try: args = fancyopts.fancyopts(args, commands.globalopts, options) except fancyopts.getopt.GetoptError: return if not args: return if precheck: strict = True norepo = commands.norepo optionalrepo = commands.optionalrepo def restorecommands(): commands.norepo = norepo commands.optionalrepo = optionalrepo cmdtable = commands.table.copy() addaliases(lui, cmdtable) else: strict = False def restorecommands(): pass cmdtable = commands.table cmd = args[0] try: aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict) except (error.AmbiguousCommand, error.UnknownCommand): restorecommands() return cmd = aliases[0] fn = entry[0] if cmd and util.safehasattr(fn, 'shell'): d = lambda: fn(ui, *args[1:]) return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {}) restorecommands()
def _checkshellalias(ui, args): cwd = os.getcwd() norepo = commands.norepo options = {} try: args = fancyopts.fancyopts(args, commands.globalopts, options) except fancyopts.getopt.GetoptError: return if not args: return _parseconfig(ui, options['config']) if options['cwd']: os.chdir(options['cwd']) path, lui = _getlocal(ui, [options['repository']]) cmdtable = commands.table.copy() addaliases(lui, cmdtable) cmd = args[0] try: aliases, entry = cmdutil.findcmd(cmd, cmdtable, lui.config("ui", "strict")) except (error.AmbiguousCommand, error.UnknownCommand): commands.norepo = norepo os.chdir(cwd) return cmd = aliases[0] fn = entry[0] if cmd and hasattr(fn, 'shell'): d = lambda: fn(ui, *args[1:]) return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {}) commands.norepo = norepo os.chdir(cwd)
cmd = aliases[0] args = aliasargs(entry[0], args) defaults = ui.config("defaults", cmd) if defaults: args = map(util.expandpath, shlex.split(defaults)) + args c = list(entry[1]) else: cmd = None c = [] # combine global options into local for o in commands.globalopts: c.append((o[0], o[1], options[o[1]], o[3])) try: args = fancyopts.fancyopts(args, c, cmdoptions, True) except fancyopts.getopt.GetoptError, inst: raise error.CommandError(cmd, inst) # separate global options back out for o in commands.globalopts: n = o[1] options[n] = cmdoptions[n] del cmdoptions[n] return (cmd, cmd and entry[0] or None, args, options, cmdoptions) def _parseconfig(ui, config): """parse the --config options from the command line""" configs = []