Adds arguments parsers for the block list and block show commands

        Args:
            subparsers: Add parsers to this subparser object
            parent_parser: The parent argparse.ArgumentParser object
354327
def add_block_parser(subparsers, parent_parser):
    
    parser = subparsers.add_parser(
        'block',
        description='Provides subcommands to display information about the '
        'blocks in the current blockchain.',
        help='Displays information on blocks in the current blockchain')

    grand_parsers = parser.add_subparsers(
        title='subcommands',
        dest='subcommand')

    grand_parsers.required = True

    description = (
        'Displays information for all blocks on the current '
        'blockchain, including the block id and number, public keys all '
        'of allsigners, and number of transactions and batches.')

    list_parser = grand_parsers.add_parser(
        'list',
        help='Displays information for all blocks on the current blockchain',
        description=description,
        parents=[base_http_parser(), base_list_parser()],
        formatter_class=argparse.RawDescriptionHelpFormatter)

    list_parser.add_argument(
        '-n',
        '--count',
        default=100,
        type=int,
        help='the number of blocks to list',
    )

    description = (
        'Displays information about the specified block on '
        'the current blockchain')

    show_parser = grand_parsers.add_parser(
        'show',
        help=description,
        description=description + '.',
        parents=[base_http_parser(), base_show_parser()],
        formatter_class=argparse.RawDescriptionHelpFormatter)
    show_parser.add_argument(
        'block_id',
        type=str,
        help='id (header_signature) of the block')
569496
def add_config_parser(subparsers, parent_parser):
    
    parser = subparsers.add_parser(
        'config',
        help='Changes genesis block settings and create, view, and '
        'vote on settings proposals',
        description='Provides subcommands to change genesis block settings '
                    'and to view, create, and vote on existing proposals.'
    )

    config_parsers = parser.add_subparsers(title="subcommands",
                                           dest="subcommand")
    config_parsers.required = True
730462
def arg_parser(self, passed_args=None):
        
        parser, subpar, remaining_argv = self._setup_parser()
        if not isinstance(passed_args, list):
            passed_args = list()

        # Extend the passed args with the remaining parsed args
        if remaining_argv:
            passed_args.extend(remaining_argv)

        optional_args = self.arguments.get('optional_args')
        if optional_args:
            self._add_opt_argument(opt_args=optional_args, arg_parser=parser)

        subparsed_args = self.arguments.get('subparsed_args')
        if subparsed_args:
            for argument, value in subparsed_args.items():
                if 'optional_args' in value:
                    optional_args = value.pop('optional_args')
                else:
                    optional_args = dict()

                if 'shared_args' in value:
                    set_shared_args = self.arguments.get('shared_args')
                    _shared_args = value.pop('shared_args', list())
                    for shared_arg in _shared_args:
                        optional_args[shared_arg] = set_shared_args[shared_arg]

                action = subpar.add_parser(
                    argument,
                    **value
                )
                action.set_defaults(parsed_command=argument)

                if optional_args:
                    self._add_opt_argument(
                        opt_args=optional_args, arg_parser=action
                    )

        positional_args = self.arguments.get('positional_args')
        if positional_args:
            for argument in positional_args.keys():
                _arg = positional_args[argument]

                parser.add_argument(
                    argument,
                    **_arg
                )

        # Return the parsed arguments as a dict
        return vars(parser.parse_args(args=passed_args))
213181
def _apply2parser(arguments, options, parser):
    
    for args, kwargs in options:
        parser.option(*args, **kwargs)
    for args, kwargs in arguments:
        parser.argument(*args, **kwargs)
    return parser
1176101
def setup_manage_parser(self, parser):
        
        parser.set_defaults(func=self.manage)
        parser.add_argument("args", nargs=argparse.REMAINDER,
                            help="arguments for django manage command")
84546
def add_arguments(self, parser):
        
        parser.add_argument('--length', default=self.length,
                            type=int, help=_('SECRET_KEY length default=%d' % self.length))

        parser.add_argument('--alphabet', default=self.allowed_chars,
                            type=str, help=_('alphabet to use default=%s' % self.allowed_chars))
305045
def add_peer_parser(subparsers, parent_parser):
    
    parser = subparsers.add_parser(
        'peer',
        help='Displays information about validator peers',
        description="Provides a subcommand to list a validator's peers")

    grand_parsers = parser.add_subparsers(title='subcommands',
                                          dest='subcommand')
    grand_parsers.required = True
    add_peer_list_parser(grand_parsers, parent_parser)
675155
def get_sub_commands(parser: argparse.ArgumentParser) -> List[str]:
    """"""
    sub_cmds = []

    # Check if this is parser has sub-commands
    if parser is not None and parser._subparsers is not None:

        # Find the _SubParsersAction for the sub-commands of this parser
        for action in parser._subparsers._actions:
            if isinstance(action, argparse._SubParsersAction):
                for sub_cmd, sub_cmd_parser in action.choices.items():
                    sub_cmds.append(sub_cmd)

                    # Look for nested sub-commands
                    for nested_sub_cmd in get_sub_commands(sub_cmd_parser):
                        sub_cmds.append('{} {}'.format(sub_cmd, nested_sub_cmd))

                break

    sub_cmds.sort()
    return sub_cmds
644356
def create_parser(self, prog_name, subcommand):
        
        return OptionParser(prog=prog_name,
                            usage=self.usage(subcommand),
                            version='',
                            add_help_option = False,
                            option_list=self.option_list)
124517
def _attach_subcommands(self):
        
        if self.subcommands:
            self.subparsers = self.parser.add_subparsers()

            for subcommand in self.subcommands:
                subparser = self.subparsers.add_parser(subcommand.name,
                                                       help=subcommand.title)
                if subcommand.handler:
                    self._register_handler(subparser, subcommand.handler)
                subcommand._init(subparser)
854273
def parser(self):
        """"""
        if self._command_parser is None:
            parents = []
            if self.need_verbose:
                parents.append(_verbose_parser)
            if self.need_settings:
                parents.append(_settings_parser)

            self._command_parser = self._main_parser.add_parser(self.name,
                                                                help=self.help,
                                                                parents=parents,
                                                                formatter_class=argparse.RawDescriptionHelpFormatter)
        return self._command_parser
119578
def add_genesis_parser(subparsers, parent_parser):
    
    parser = subparsers.add_parser(
        'genesis',
        help='Creates the genesis.batch file for initializing the validator',
        description='Generates the genesis.batch file for '
        'initializing the validator.',
        epilog='This command generates a serialized GenesisData protobuf '
        'message and stores it in the genesis.batch file. One or more input '
        'files (optional) can contain serialized BatchList protobuf messages '
        'to add to the GenesisData. The output shows the location of this '
        'file. By default, the genesis.batch file is stored in '
        '/var/lib/sawtooth. If $SAWTOOTH_HOME is set, the location is '
        '$SAWTOOTH_HOME/data/genesis.batch. Use the --output option to change '
        'the name of the file.',
        parents=[parent_parser])

    parser.add_argument(
        '-o', '--output',
        type=str,
        help='choose the output file for GenesisData')

    parser.add_argument(
        'input_file',
        nargs='*',
        type=str,
        help='file or files containing batches to add to the resulting '
        'GenesisData')
947753
def add_subparser(subparsers):
    
    parser = subparsers.add_parser("server", help="Run a bcbio-nextgen server allowing remote job execution.")
    parser.add_argument("-c", "--config", help=("Global YAML configuration file specifying system details."
                                                "Defaults to installed bcbio_system.yaml"))
    parser.add_argument("-p", "--port", help="Port to listen on (default 8080)",
                        default=8080, type=int)
    parser.add_argument("-n", "--cores", help="Cores to use when processing locally when not requested (default 1)",
                        default=1, type=int)
    parser.add_argument("-d", "--biodata_dir", help="Directory with biological data",
                        default="/mnt/biodata", type=str)
    return parser
1078906
def add_identity_parser(subparsers, parent_parser):
    
    # identity
    parser = subparsers.add_parser(
        'identity',
        help='Works with optional roles, policies, and permissions',
        description='Provides subcommands to work with roles and policies.')

    identity_parsers = parser.add_subparsers(
        title="subcommands",
        dest="subcommand")

    identity_parsers.required = True

    # policy
    policy_parser = identity_parsers.add_parser(
        'policy',
        help='Provides subcommands to display existing policies and create '
        'new policies',
        description='Provides subcommands to list the current policies '
        'stored in state and to create new policies.')

    policy_parsers = policy_parser.add_subparsers(
        title='policy',
        dest='policy_cmd')

    policy_parsers.required = True

    # policy create
    create_parser = policy_parsers.add_parser(
        'create',
        help='Creates batches of sawtooth-identity transactions for setting a '
        'policy',
        description='Creates a policy that can be set to a role or changes a '
        'policy without resetting the role.')

    create_parser.add_argument(
        '-k', '--key',
        type=str,
        help='specify the signing key for the resulting batches')

    create_target_group = create_parser.add_mutually_exclusive_group()

    create_target_group.add_argument(
        '-o', '--output',
        type=str,
        help='specify the output filename for the resulting batches')

    create_target_group.add_argument(
        '--url',
        type=str,
        help="identify the URL of a validator's REST API",
        default='http://localhost:8008')

    create_parser.add_argument(
        '--wait',
        type=int,
        default=15,
        help="set time, in seconds, to wait for the policy to commit when "
             "submitting to the REST API.")

    create_parser.add_argument(
        'name',
        type=str,
        help='name of the new policy')

    create_parser.add_argument(
        'rule',
        type=str,
        nargs="+",
        help='rule with the format "PERMIT_KEY <key>" or "DENY_KEY <key> '
        '(multiple "rule" arguments can be specified)')

    # policy list
    list_parser = policy_parsers.add_parser(
        'list',
        help='Lists the current policies',
        description='Lists the policies that are currently set in state.')

    list_parser.add_argument(
        '--url',
        type=str,
        help="identify the URL of a validator's REST API",
        default='http://localhost:8008')

    list_parser.add_argument(
        '--format',
        default='default',
        choices=['default', 'csv', 'json', 'yaml'],
        help='choose the output format')

    # role
    role_parser = identity_parsers.add_parser(
        'role',
        help='Provides subcommands to display existing roles and create '
        'new roles',
        description='Provides subcommands to list the current roles '
        'stored in state and to create new roles.')

    role_parsers = role_parser.add_subparsers(
        title='role',
        dest='role_cmd')

    role_parsers.required = True

    # role create
    create_parser = role_parsers.add_parser(
        'create',
        help='Creates a new role that can be used to enforce permissions',
        description='Creates a new role that can be used to enforce '
        'permissions.')

    create_parser.add_argument(
        '-k', '--key',
        type=str,
        help='specify the signing key for the resulting batches')

    create_parser.add_argument(
        '--wait',
        type=int,
        default=15,
        help='set time, in seconds, to wait for a role to commit '
        'when submitting to  the REST API.')

    create_target_group = create_parser.add_mutually_exclusive_group()

    create_target_group.add_argument(
        '-o', '--output',
        type=str,
        help='specify the output filename for the resulting batches')

    create_target_group.add_argument(
        '--url',
        type=str,
        help="the URL of a validator's REST API",
        default='http://localhost:8008')

    create_parser.add_argument(
        'name',
        type=str,
        help='name of the role')

    create_parser.add_argument(
        'policy',
        type=str,
        help='identify policy that role will be restricted to')

    # role list
    list_parser = role_parsers.add_parser(
        'list',
        help='Lists the current keys and values of roles',
        description='Displays the roles that are currently set in state.')

    list_parser.add_argument(
        '--url',
        type=str,
        help="identify the URL of a validator's REST API",
        default='http://localhost:8008')

    list_parser.add_argument(
        '--format',
        default='default',
        choices=['default', 'csv', 'json', 'yaml'],
        help='choose the output format')
378355
def add_compare_chains_parser(subparsers, parent_parser):
    
    parser = subparsers.add_parser(
        'compare-chains',
        help='Compare chains from different nodes.',
        description=(
            'Compute and display information about how the chains at '
            'different nodes differ.'
        ),
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog='''
By default, prints a table of summary data and a table of per-node data with
the following fields. Pass --tree for a fork graph.

COMMON ANCESTOR
    The most recent block that all chains have in common.

COMMON HEIGHT
    Let min_height := the minimum height of any chain across all nodes passed
    in. COMMON HEIGHT = min_height.

HEAD
    The block id of the most recent block on a given chain.

HEIGHT
    The block number of the most recent block on a given chain.

LAG
    Let max_height := the maximum height of any chain across all nodes passed
    in. LAG = max_height - HEIGHT for a given chain.

DIVERG
    Let common_ancestor_height := the height of the COMMON ANCESTOR.
    DIVERG = HEIGHT - common_ancestor_height

''',
        parents=[parent_parser, base_multinode_parser()])

    parser.add_argument(
        '-l',
        '--limit',
        default=25,
        type=int,
        help='the number of blocks to request at a time',
    )

    parser.add_argument(
        '--table',
        action='store_true',
        help='Print out a fork table for all nodes since the common ancestor.')

    parser.add_argument(
        '--tree',
        action='store_true',
        help='Print out a fork tree for all nodes since the common ancestor.')
809580
def add_settings_parser(subparsers, parent_parser):
    
    # The following parser is for the settings subsection of commands.  These
    # commands display information about the currently applied on-chain
    # settings.

    settings_parser = subparsers.add_parser(
        'settings',
        help='Displays on-chain settings',
        description='Displays the values of currently active on-chain '
                    'settings.')

    settings_parsers = settings_parser.add_subparsers(
        title='settings',
        dest='settings_cmd')
    settings_parsers.required = True

    list_parser = settings_parsers.add_parser(
        'list',
        help='Lists the current keys and values of on-chain settings',
        description='List the current keys and values of on-chain '
                    'settings. The content can be exported to various '
                    'formats for external consumption.'
    )

    list_parser.add_argument(
        '--url',
        type=str,
        help="identify the URL of a validator's REST API",
        default='http://localhost:8008')

    list_parser.add_argument(
        '--filter',
        type=str,
        default='',
        help='filters keys that begin with this value')

    list_parser.add_argument(
        '--format',
        default='default',
        choices=['default', 'csv', 'json', 'yaml'],
        help='choose the output format')
941664
def add_arguments(self, parser):
        
        subparsers = parser.add_subparsers(help='sub-command help',
                                           dest='command')

        add_parser = partial(_add_subparser, subparsers, parser)

        add_parser('list', help="list concurrency triggers")
        add_parser('drop', help="drop  concurrency triggers")
        add_parser('create', help="create concurrency triggers")

        parser.add_argument('-d', '--database',
                            action='store',
                            dest='database',
                            default=None,
                            help='limit to this database')

        parser.add_argument('-t', '--trigger',
                            action='store',
                            dest='trigger',
                            default=None,
                            help='limit to this trigger name')