Process the command table and load it into the parser

        :param cmd_tbl: A dictionary containing the commands
        :type cmd_tbl: dict
350899
def load_command_table(self, command_loader):
        
        cmd_tbl = command_loader.command_table
        grp_tbl = command_loader.command_group_table
        if not cmd_tbl:
            raise ValueError('The command table is empty. At least one command is required.')
        # If we haven't already added a subparser, we
        # better do it.
        if not self.subparsers:
            sp = self.add_subparsers(dest='_command')
            sp.required = True
            self.subparsers = {(): sp}

        for command_name, metadata in cmd_tbl.items():
            subparser = self._get_subparser(command_name.split(), grp_tbl)
            command_verb = command_name.split()[-1]
            # To work around http://bugs.python.org/issue9253, we artificially add any new
            # parsers we add to the "choices" section of the subparser.
            subparser = self._get_subparser(command_name.split(), grp_tbl)
            deprecate_info = metadata.deprecate_info
            if not subparser or (deprecate_info and deprecate_info.expired()):
                continue
            # inject command_module designer's help formatter -- default is HelpFormatter
            fc = metadata.formatter_class or argparse.HelpFormatter

            command_parser = subparser.add_parser(command_verb,
                                                  description=metadata.description,
                                                  parents=self.parents,
                                                  conflict_handler='error',
                                                  help_file=metadata.help,
                                                  formatter_class=fc,
                                                  cli_help=self.cli_help)
            command_parser.cli_ctx = self.cli_ctx
            command_validator = metadata.validator
            argument_validators = []
            argument_groups = {}
            for arg in metadata.arguments.values():

                # don't add deprecated arguments to the parser
                deprecate_info = arg.type.settings.get('deprecate_info', None)
                if deprecate_info and deprecate_info.expired():
                    continue

                if arg.validator:
                    argument_validators.append(arg.validator)
                if arg.arg_group:
                    try:
                        group = argument_groups[arg.arg_group]
                    except KeyError:
                        # group not found so create
                        group_name = '{} Arguments'.format(arg.arg_group)
                        group = command_parser.add_argument_group(arg.arg_group, group_name)
                        argument_groups[arg.arg_group] = group
                    param = CLICommandParser._add_argument(group, arg)
                else:
                    param = CLICommandParser._add_argument(command_parser, arg)
                param.completer = arg.completer
                param.deprecate_info = arg.deprecate_info
            command_parser.set_defaults(
                func=metadata,
                command=command_name,
                _command_validator=command_validator,
                _argument_validators=argument_validators,
                _parser=command_parser)
259754
def _make_cmd_list(cmd_list):
    
    cmd = ''
    for i in cmd_list:
        cmd = cmd + '"' + i + '",'
    cmd = cmd[:-1]
    return cmd
34827
def get_parameter_tbl(self, parameter):
        
        par = []
        for entry in parameter.findall('Entry'):
            instance = defaultdict(list)
            instance['Instance'] = entry.find('Instance').text.split()
            if entry.find('ProbTable') is None:
                instance['ValueTable'] = entry.find('ValueTable').text.split()
            else:
                instance['ProbTable'] = entry.find('ProbTable').text.split()
            par.append(instance)
        return par
714539
def cmdline(argv, flags):
    """"""
    rules = dict([(flag, {'flags': ["--%s" % flag]}) for flag in flags])
    return parse(argv, rules)
631981
def cmdline(self, **kwargs):
        

        args = [self.executable]
        indexed_args = []

        for key, value in kwargs.iteritems():
            parameter = self[key]
            if value != parameter.default:
                no_value = parameter.type == 'boolean'

                if parameter.longflag:  # use longflag where possible
                    args.append("--%s" % parameter.longflag)
                    if no_value:
                        args.append(str(value))
                elif parameter.flag:
                    args.append("-%s" % parameter.flag)
                    if no_value:
                        args.append(str(value))
                elif parameter.index:
                    indexed_args.insert(int(parameter.index), str(value))

        return args + indexed_args
1035440
def _run_cmd(self, command):
        
        if self.throttle:
            tables = self.engine.describe_all(False)
            limiter = self.throttle.get_limiter(tables)
        else:
            limiter = None
        self.engine.rate_limit = limiter
        results = self.engine.execute(command)
        if results is None:
            pass
        elif isinstance(results, basestring):
            print(results)
        else:
            with self.display() as ostream:
                formatter = FORMATTERS[self.conf["format"]](
                    results,
                    ostream,
                    pagesize=self.conf["pagesize"],
                    width=self.conf["width"],
                )
                formatter.display()
        print_count = 0
        total = None
        for (cmd_fragment, capacity) in self.engine.consumed_capacities:
            total += capacity
            print(cmd_fragment)
            print(indent(str(capacity)))
            print_count += 1
        if print_count > 1:
            print("TOTAL")
            print(indent(str(total)))
1219492
def load_arguments(self, command):
        
        from knack.arguments import ArgumentsContext

        self.cli_ctx.raise_event(EVENT_CMDLOADER_LOAD_ARGUMENTS, cmd_tbl=self.command_table, command=command)
        try:
            self.command_table[command].load_arguments()
        except KeyError:
            return

        # ensure global 'cmd' is ignored
        with ArgumentsContext(self, '') as c:
            c.ignore('cmd')

        self._apply_parameter_info(command, self.command_table[command])
865915
def tables(self):
        
        from .table import Table
        return [Table(tbl, self) for tbl in self._element.tbl_lst]
1344180
def consume(self, cwd=None):
        
        first_pass = Grammar.overall.parseString(self.string)
        lowered = { key.lower(): val for key, val in first_pass.iteritems() }

        self.commands = ['\n'.join(self._get('commands', lowered))]
        self.job_options = self._get('job_options', lowered)
        self.global_options = self._get('options', lowered)

        self.files = self._get('files', lowered)
        self.paths = self._get('paths', lowered)

        self.files = self._parse(self.files, Grammar.file, True)
        self.paths = self._parse(self.paths, Grammar.path, True)
        self.job_options = self._parse(self.job_options, Grammar.line)

        try:
            command_lines = self._parse(self.commands, Grammar.command_lines)[0]
        except IndexError:
            raise ValueError('Did you write any commands?')

        self.commands = []
        for command_line in command_lines:
            comments, command = command_line
            self.commands.append([comments.asList(),
                self._parse([''.join(command)], Grammar.command)])

        self.job_options = [opt.asList() for opt in self.job_options]

        self.paths = ctf.get_paths(self.paths)
        self.files = ctf.get_files(self.files)

        self.paths.reverse()
        self.files.reverse()
        self.commands.reverse()

        return ctf.get_command_templates(self.commands, self.files[:],
            self.paths[:], self.job_options)
986587
def cmd_iter(
            self,
            tgt,
            fun,
            arg=(),
            timeout=None,
            tgt_type='glob',
            ret='',
            kwarg=None,
            **kwargs):
        '''
        
        '''
        ssh = self._prep_ssh(
                tgt,
                fun,
                arg,
                timeout,
                tgt_type,
                kwarg,
                **kwargs)
        for ret in ssh.run_iter(jid=kwargs.get('jid', None)):
            yield ret
1288691
def db_command(parser_args):
    
    from synergy.db.manager import db_manager

    if parser_args.reset:
        db_manager.reset_db()
        # initialize DB with the context.process_context entries
        parser_args.update = True

    if parser_args.update:
        db_manager.update_db()
680514
def command_line_parsed(
            self,
            available_plugins: Set[Type[Plugin]],
            args_command_list: Any,
            malformed_servers: List[ServerStringParsingError]
    ) -> None:
        
238196
def handle_cmd(self, cmd):
        """"""
        cmd = cmd.strip()
        segments = []
        for s in cmd.split():
            # remove bash-like comments
            if s.startswith('#'):
                break
            # TODO implement escape sequences (also for \#)
            segments.append(s)
        args = []
        if not len(segments):
            return
        # process more specific commands first
        while segments:
            cur_cmd = "_".join(segments)
            if cur_cmd in self._cmd_methods:
                argc = self._cmd_argc[cur_cmd]
                if argc is not None and len(args) != argc:
                    msg('command {0} expects {1} argument(s), got {2}',
                        " ".join(segments), argc, len(args))
                    return
                self._cmd_methods[cur_cmd](args)
                return
            args.insert(0, segments.pop())
        # invalid command
        prefix = '_'.join(args) + '_'
        matches = filter(
            lambda cmd: cmd.startswith(prefix), self._cmd_methods.keys())
        candidates = set([])
        for m in matches:
            if len(m) <= len(prefix):
                continue
            m = m[len(prefix):]
            if '_' in m:
                m = m[:m.index('_')]
            candidates.add(m)
        if len(candidates):
            msg('command "{0}" needs more arguments:', ' '.join(args))
            for c in candidates:
                msg('    {0}', c)
        else:
            msg('command "{0}" invalid; type ' +
                'help or use <TAB> for a list of commands',
                ' '.join(args))
1017810
def list_cmd(cmd, src_path):
  ''' 
  '''
  cmd.extend([src_path])

  logger.debug(u'Executing cmd: %s' % cmd)
  result = execute(cmd)
  if not result:
    return None

  logger.debug(u'Raw result: %s' % result)
  list_dict = json.loads(result)
  pages = parse_pages(src_path, list_dict)
  return pages
1258295
def _execute_select_commands(self, source, commands):
        """"""
        rows = {}
        for tbl, command in tqdm(commands, total=len(commands), desc='Executing {0} select queries'.format(source)):
            # Add key to dictionary
            if tbl not in rows:
                rows[tbl] = []
            rows[tbl].extend(self.fetch(command, commit=True))
        self._commit()
        return rows
1252210
def load_subcommand(subparsers):
    """"""
    parser_analyze = subparsers.add_parser('echo_conf', help='Echo sample configuration file')
    parser_analyze.set_defaults(func=echo_conf)
757338
def do_commander(self):
        """"""
        # Flatten commands list then extract primary command and its arguments.
        if self._args.commands is not None:
            cmds = []
            for cmd in self._args.commands:
                cmds.append(flatten_args(split_command_line(arg) for arg in cmd))
        else:
            cmds = None

        # Enter REPL.
        PyOCDCommander(self._args, cmds).run()