Insantiates the subparsers for all commands
167789
def subparsers(self):
        
        if self._subparsers is None:
            apkw = {
                'title': 'commands',
                'description': 'Commands for the %s program' % self.parser.prog,
            }
            self._subparsers = self.parser.add_subparsers(**apkw)
        return self._subparsers
213881
def parse():
    """"""

    # Build the list of subcommand modules
    modnames = [mod for (_, mod, _)
                in pkgutil.iter_modules(payu.subcommands.__path__,
                                        prefix=payu.subcommands.__name__ + '.')
                if mod.endswith('_cmd')]

    subcmds = [importlib.import_module(mod) for mod in modnames]

    # Construct the subcommand parser
    parser = argparse.ArgumentParser()
    parser.add_argument('--version', action='version',
                        version='payu {0}'.format(payu.__version__))

    subparsers = parser.add_subparsers()

    for cmd in subcmds:
        cmd_parser = subparsers.add_parser(cmd.title, **cmd.parameters)
        cmd_parser.set_defaults(run_cmd=cmd.runcmd)

        for arg in cmd.arguments:
            cmd_parser.add_argument(*arg['flags'], **arg['parameters'])

    # Display help if no arguments are provided
    if len(sys.argv) == 1:
        parser.print_help()
    else:
        args = vars(parser.parse_args())
        run_cmd = args.pop('run_cmd')
        run_cmd(**args)
222641
def get_parser(self):
        
        parser = self.parser_cls(prog=self.prog_name, usage=self.get_usage(),
            stream=self.stderr)
        subparsers = parser.add_subparsers(
            title='subcommands',
        )
        for name, command in self.registry.items():
            cmdparser = subparsers.add_parser(name, help=command.help)
            for argument in command.get_args():
                cmdparser.add_argument(*argument.args, **argument.kwargs)
            command.setup_parser(parser, cmdparser)
            cmdparser.set_defaults(func=command.handle)

        return parser
896128
def init_parser(cls, parser):
        """"""
        subparsers = parser.add_subparsers(title='Search domain')

        # Compound subcommand
        parser_compound = subparsers.add_parser(
            'compound', help='Search in compounds')
        parser_compound.set_defaults(which='compound')
        parser_compound.add_argument(
            '--id', '-i', dest='id', metavar='id',
            action=FilePrefixAppendAction, type=text_type, default=[],
            help='Compound ID')
        parser_compound.add_argument(
            '--name', '-n', dest='name', metavar='name',
            action=FilePrefixAppendAction, type=text_type, default=[],
            help='Name of compound')

        # Reaction subcommand
        parser_reaction = subparsers.add_parser(
            'reaction', help='Search in reactions')
        parser_reaction.set_defaults(which='reaction')
        parser_reaction.add_argument(
            '--id', '-i', dest='id', metavar='id',
            action=FilePrefixAppendAction, type=str, default=[],
            help='Reaction ID')
        parser_reaction.add_argument(
            '--compound', '-c', dest='compound', metavar='compound',
            action=FilePrefixAppendAction, type=str, default=[],
            help='Comma-separated list of compound IDs')
314371
def add_cmd(self, name, help=None, func=None):
        
        if self.subparsers is None:
            self.subparsers = self.add_subparsers(
                title="sub-commands",
                help=help or 'sub-commands',
            )

        parser = self.subparsers.add_parser(
            name,
            help=help,
        )
        if func is not None:
            parser.set_defaults(_func=func)
        return parser
1214404
def generate_prepare_subparser(subparsers):
    """"""
    parser = subparsers.add_parser(
        'prepare', description=constants.PREPARE_DESCRIPTION,
        epilog=constants.PREPARE_EPILOG, formatter_class=ParagraphFormatter,
        help=constants.PREPARE_HELP)
    parser.set_defaults(func=prepare_xml)
    utils.add_common_arguments(parser)
    parser.add_argument('-s', '--source', dest='source',
                        choices=constants.TEI_SOURCE_CHOICES,
                        default=constants.TEI_SOURCE_CBETA_GITHUB,
                        help=constants.PREPARE_SOURCE_HELP,
                        metavar='SOURCE')
    parser.add_argument('input', help=constants.PREPARE_INPUT_HELP,
                        metavar='INPUT')
    parser.add_argument('output', help=constants.PREPARE_OUTPUT_HELP,
                        metavar='OUTPUT')
1080824
def addSubparser(subparsers, subcommand, description):
    
    parser = subparsers.add_parser(
        subcommand, description=description, help=description)
    return parser
395130
def _create_parser() -> ArgumentParser:
    
    parser = ArgumentParser(prog=EXECUTABLE_NAME, description=f"{DESCRIPTION} (v{VERSION})")
    parser.add_argument(
        f"-{VERBOSE_SHORT_PARAMETER}", action="count", default=0,
        help="increase the level of log verbosity (add multiple increase further)")
    subparsers = parser.add_subparsers(dest=ACTION_CLI_PARAMETER_ACCESS, help="action")

    unlock_subparser = subparsers.add_parser(Action.UNLOCK.value, help="release a lock")
    unlock_subparser.add_argument(
        f"-{REGEX_KEY_ENABLED_SHORT_PARAMETER}", action="store_true", default=DEFAULT_REGEX_KEY_ENABLED,
        help="whether the key should be treated as a regular expression and to release all matching locks")

    lock_subparser = subparsers.add_parser(Action.LOCK.value, help="acquire a lock")
    lock_and_execute_subparser = subparsers.add_parser(Action.EXECUTE.value, help="call executable whilst holding lock")

    for subparser in (lock_subparser, lock_and_execute_subparser):
        subparser.add_argument(
            f"--{SESSION_TTL_LONG_PARAMETER}", type=float, default=DEFAULT_SESSION_TTL,
            help=f"time to live (ttl) in seconds of the session that will be created to hold the lock. Must be between "
                 f"{MIN_LOCK_TIMEOUT_IN_SECONDS}s and {MAX_LOCK_TIMEOUT_IN_SECONDS}s (inclusive). If set to "
                 f"{NO_EXPIRY_SESSION_TTL_CLI_PARAMETER_VALUE}, the session will not expire")
        subparser.add_argument(
            f"--{NON_BLOCKING_LONG_PARAMETER}", action="store_true",
            default=DEFAULT_NON_BLOCKING, help="do not block if cannot lock straight away")
        subparser.add_argument(
            f"--{TIMEOUT_LONG_PARAMETER}", default=DEFAULT_TIMEOUT, type=float,
            help="give up trying to acquire the key after this many seconds (where 0 is never)")
        subparser.add_argument(
            f"--{METADATA_LONG_PARAMETER}", default=DEFAULT_METADATA, type=str, action=_ParseJsonAction,
            help="additional metadata to add to the lock information (will be converted to JSON)")
        subparser.add_argument(
            f"--{ON_BEFORE_LOCK_LONG_PARAMETER}", default=[], type=str, nargs="+", action="append",
            help="path to executable that is to be called before an attempt is made to acquire a lock, where the lock "
                 "key is passed as the first argument. Any failures of this executable are ignored")
        subparser.add_argument(
            f"--{ON_LOCK_ALREADY_LOCKED_LONG_PARAMETER}", default=[], type=str, nargs="+", action="append",
            help="path to executable that is to be called after an attempt has been made to acquire a lock but failed "
                 "due to the lock already been taken, where the lock key is passed as the first argument. Any failures "
                 "of this executable are ignored")
        subparser.add_argument(
            f"-{LOCK_POLL_INTERVAL_SHORT_PARAMETER}", default=DEFAULT_LOCK_POLL_INTERVAL_GENERATOR(1), type=float,
            help="number of seconds between polls to acquire a locked lock")

    # XXX: probably a better way of iterating subparsers on `subparsers`
    for subparser in [unlock_subparser, lock_subparser, lock_and_execute_subparser]:
        subparser.add_argument(
            KEY_PARAMETER, type=str, help="the lock identifier")

    lock_and_execute_subparser.add_argument(
        EXECUTABLE_PARAMETER, type=str, help="to execute in shell")

    return parser
881200
def setup_parser(sub_parsers):
    
    parser = sub_parsers.add_parser("index", prog="law index", description="Create or update the"
        " (human-readable) law task index file ({}). This is only required for the shell"
        " auto-completion.".format(Config.instance().get("core", "index_file")))

    parser.add_argument("--modules", "-m", nargs="+", help="additional modules to traverse")
    parser.add_argument("--no-externals", "-e", action="store_true", help="skip external tasks")
    parser.add_argument("--remove", "-r", action="store_true", help="remove the index file and"
        " exit")
    parser.add_argument("--location", "-l", action="store_true", help="print the location of the"
        " index file and exit")
    parser.add_argument("--verbose", "-v", action="store_true", help="verbose output")
780369
def build(sub_parser, cmds):
    

    res = {}
    for cmd in cmds:
        res[cmd.name] = cmd(sub_parser)
    # end for cmd in cmds

    return res
690620
def register(self, command):
        
        command = command()
        if command.name in self.commands:
            raise ConsoleError(
                "Command %s already registered!" % command.name
            )

        command.create_parser(self.subparsers)
        self.commands[command.name] = command
211668
def setup_parser(sub_parsers):
    
    parser = sub_parsers.add_parser("software", prog="law software", description="Create or update"
        " the law software cache ({}). This is only required for some sandboxes that need to"
        " forward software into containers.".format(get_sw_dir()))

    parser.add_argument("--remove", "-r", action="store_true", help="remove the software cache"
        " directory and exit")
    parser.add_argument("--location", "-l", action="store_true", help="print the location of the"
        " software cache directory and exit")
355436
def parse_args(self, ctx, args):
        """"""
        if args and args[0] in self.commands:
            args.insert(0, '')
        super(OptionalGroup, self).parse_args(ctx, args)
669348
def main(prog: str = None,
         subcommand_overrides: Dict[str, Subcommand] = {}) -> None:
    
    # pylint: disable=dangerous-default-value
    parser = ArgumentParserWithDefaults(description="Run AllenNLP", usage='%(prog)s', prog=prog)
    parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)

    subparsers = parser.add_subparsers(title='Commands', metavar='')

    subcommands = {
            # Default commands
            "configure": Configure(),
            "train": Train(),
            "evaluate": Evaluate(),
            "predict": Predict(),
            "make-vocab": MakeVocab(),
            "elmo": Elmo(),
            "fine-tune": FineTune(),
            "dry-run": DryRun(),
            "test-install": TestInstall(),
            "find-lr": FindLearningRate(),
            "print-results": PrintResults(),
            # Superseded by overrides
            **subcommand_overrides
    }

    for name, subcommand in subcommands.items():
        subparser = subcommand.add_subparser(name, subparsers)
        # configure doesn't need include-package because it imports
        # whatever classes it needs.
        if name != "configure":
            subparser.add_argument('--include-package',
                                   type=str,
                                   action='append',
                                   default=[],
                                   help='additional packages to include')

    args = parser.parse_args()

    # If a subparser is triggered, it adds its work as `args.func`.
    # So if no such attribute has been added, no subparser was triggered,
    # so give the user some help.
    if 'func' in dir(args):
        # Import any additional modules needed (to register custom classes).
        for package_name in getattr(args, 'include_package', ()):
            import_submodules(package_name)
        args.func(args)
    else:
        parser.print_help()
1228418
def add_command(subparsers):
  """"""

  parser = subparsers.add_parser('create', help=create.__doc__)

  parser.add_argument('-R', '--recreate', action='store_true', help="If set, I'll first erase the current database")
  parser.add_argument('-v', '--verbose', action='count', help="Do SQL operations in a verbose way?")
  parser.add_argument('-D', '--imagedir', metavar='DIR', default='/home/bob/BTAS_Keystroke_files_SingleFile', help="Change the relative path to the directory containing the images of the ATVS Keystroke database.")

  parser.set_defaults(func=create)
259134
def generate_align_subparser(subparsers):
    """"""
    parser = subparsers.add_parser(
        'align', description=constants.ALIGN_DESCRIPTION,
        epilog=constants.ALIGN_EPILOG,
        formatter_class=ParagraphFormatter, help=constants.ALIGN_HELP)
    parser.set_defaults(func=align_results)
    utils.add_common_arguments(parser)
    parser.add_argument('-m', '--minimum', default=20,
                        help=constants.ALIGN_MINIMUM_SIZE_HELP, type=int)
    utils.add_corpus_arguments(parser)
    parser.add_argument('output', help=constants.ALIGN_OUTPUT_HELP,
                        metavar='OUTPUT')
    parser.add_argument('results', help=constants.RESULTS_RESULTS_HELP,
                        metavar='RESULTS')
324517
def registerParser(self, parser):
        

        if not isinstance(parser, Subparser):
            raise TypeError("%s is not an instance of a subparser." % parser)

        self.parsers.append(parser)