def setup_parser()

in lib/ramble/spack/cmd/buildcache.py [0:0]


def setup_parser(subparser):
    setup_parser.parser = subparser
    subparsers = subparser.add_subparsers(help='buildcache sub-commands')

    create = subparsers.add_parser('create', help=create_fn.__doc__)
    create.add_argument('-r', '--rel', action='store_true',
                        help="make all rpaths relative" +
                             " before creating tarballs.")
    create.add_argument('-f', '--force', action='store_true',
                        help="overwrite tarball if it exists.")
    create.add_argument('-u', '--unsigned', action='store_true',
                        help="create unsigned buildcache" +
                             " tarballs for testing")
    create.add_argument('-a', '--allow-root', action='store_true',
                        help="allow install root string in binary files " +
                             "after RPATH substitution")
    create.add_argument('-k', '--key', metavar='key',
                        type=str, default=None,
                        help="Key for signing.")
    output = create.add_mutually_exclusive_group(required=True)
    output.add_argument('-d', '--directory',
                        metavar='directory',
                        type=str,
                        help="local directory where " +
                             "buildcaches will be written.")
    output.add_argument('-m', '--mirror-name',
                        metavar='mirror-name',
                        type=str,
                        help="name of the mirror where " +
                             "buildcaches will be written.")
    output.add_argument('--mirror-url',
                        metavar='mirror-url',
                        type=str,
                        help="URL of the mirror where " +
                             "buildcaches will be written.")
    create.add_argument('--rebuild-index', action='store_true',
                        default=False, help="Regenerate buildcache index " +
                                            "after building package(s)")
    create.add_argument('--spec-file', default=None,
                        help=('Create buildcache entry for spec from json or ' +
                              'yaml file'))
    create.add_argument('--only', default='package,dependencies',
                        dest='things_to_install',
                        choices=['package', 'dependencies'],
                        help=('Select the buildcache mode. the default is to'
                              ' build a cache for the package along with all'
                              ' its dependencies. Alternatively, one can'
                              ' decide to build a cache for only the package'
                              ' or only the dependencies'))
    arguments.add_common_arguments(create, ['specs'])
    create.set_defaults(func=create_fn)

    install = subparsers.add_parser('install', help=install_fn.__doc__)
    install.add_argument('-f', '--force', action='store_true',
                         help="overwrite install directory if it exists.")
    install.add_argument('-m', '--multiple', action='store_true',
                         help="allow all matching packages ")
    install.add_argument('-a', '--allow-root', action='store_true',
                         help="allow install root string in binary files " +
                              "after RPATH substitution")
    install.add_argument('-u', '--unsigned', action='store_true',
                         help="install unsigned buildcache" +
                              " tarballs for testing")
    install.add_argument('-o', '--otherarch', action='store_true',
                         help="install specs from other architectures" +
                              " instead of default platform and OS")

    arguments.add_common_arguments(install, ['specs'])
    install.set_defaults(func=install_fn)

    listcache = subparsers.add_parser('list', help=list_fn.__doc__)
    arguments.add_common_arguments(listcache, ['long', 'very_long'])
    listcache.add_argument('-v', '--variants',
                           action='store_true',
                           dest='variants',
                           help='show variants in output (can be long)')
    listcache.add_argument('-a', '--allarch', action='store_true',
                           help="list specs for all available architectures" +
                                 " instead of default platform and OS")
    arguments.add_common_arguments(listcache, ['specs'])
    listcache.set_defaults(func=list_fn)

    keys = subparsers.add_parser('keys', help=keys_fn.__doc__)
    keys.add_argument(
        '-i', '--install', action='store_true',
        help="install Keys pulled from mirror")
    keys.add_argument(
        '-t', '--trust', action='store_true',
        help="trust all downloaded keys")
    keys.add_argument('-f', '--force', action='store_true',
                      help="force new download of keys")
    keys.set_defaults(func=keys_fn)

    preview = subparsers.add_parser('preview', help=preview_fn.__doc__)
    arguments.add_common_arguments(preview, ['installed_specs'])
    preview.set_defaults(func=preview_fn)

    # Check if binaries need to be rebuilt on remote mirror
    check = subparsers.add_parser('check', help=check_fn.__doc__)
    check.add_argument(
        '-m', '--mirror-url', default=None,
        help='Override any configured mirrors with this mirror url')

    check.add_argument(
        '-o', '--output-file', default=None,
        help='File where rebuild info should be written')

    # used to construct scope arguments below
    scopes = spack.config.scopes()
    scopes_metavar = spack.config.scopes_metavar

    check.add_argument(
        '--scope', choices=scopes, metavar=scopes_metavar,
        default=spack.config.default_modify_scope(),
        help="configuration scope containing mirrors to check")

    check.add_argument(
        '-s', '--spec', default=None,
        help='Check single spec instead of release specs file')

    check.add_argument(
        '--spec-file', default=None,
        help=('Check single spec from json or yaml file instead of release ' +
              'specs file'))

    check.set_defaults(func=check_fn)

    # Download tarball and specfile
    download = subparsers.add_parser('download', help=download_fn.__doc__)
    download.add_argument(
        '-s', '--spec', default=None,
        help="Download built tarball for spec from mirror")
    download.add_argument(
        '--spec-file', default=None,
        help=("Download built tarball for spec (from json or yaml file) " +
              "from mirror"))
    download.add_argument(
        '-p', '--path', default=None,
        help="Path to directory where tarball should be downloaded")
    download.set_defaults(func=download_fn)

    # Get buildcache name
    getbuildcachename = subparsers.add_parser('get-buildcache-name',
                                              help=get_buildcache_name_fn.__doc__)
    getbuildcachename.add_argument(
        '-s', '--spec', default=None,
        help='Spec string for which buildcache name is desired')
    getbuildcachename.add_argument(
        '--spec-file', default=None,
        help=('Path to spec json or yaml file for which buildcache name is ' +
              'desired'))
    getbuildcachename.set_defaults(func=get_buildcache_name_fn)

    # Given the root spec, save the yaml of the dependent spec to a file
    savespecfile = subparsers.add_parser('save-specfile',
                                         help=save_specfile_fn.__doc__)
    savespecfile.add_argument(
        '--root-spec', default=None,
        help='Root spec of dependent spec')
    savespecfile.add_argument(
        '--root-specfile', default=None,
        help='Path to json or yaml file containing root spec of dependent spec')
    savespecfile.add_argument(
        '-s', '--specs', default=None,
        help='List of dependent specs for which saved yaml is desired')
    savespecfile.add_argument(
        '--specfile-dir', default=None,
        help='Path to directory where spec yamls should be saved')
    savespecfile.set_defaults(func=save_specfile_fn)

    # Copy buildcache from some directory to another mirror url
    copy = subparsers.add_parser('copy', help=copy_fn.__doc__)
    copy.add_argument(
        '--base-dir', default=None,
        help='Path to mirror directory (root of existing buildcache)')
    copy.add_argument(
        '--spec-file', default=None,
        help=('Path to spec json or yaml file representing buildcache entry to' +
              ' copy'))
    copy.add_argument(
        '--destination-url', default=None,
        help='Destination mirror url')
    copy.set_defaults(func=copy_fn)

    # Sync buildcache entries from one mirror to another
    sync = subparsers.add_parser('sync', help=sync_fn.__doc__)
    source = sync.add_mutually_exclusive_group(required=True)
    source.add_argument('--src-directory',
                        metavar='DIRECTORY',
                        type=str,
                        help="Source mirror as a local file path")
    source.add_argument('--src-mirror-name',
                        metavar='MIRROR_NAME',
                        type=str,
                        help="Name of the source mirror")
    source.add_argument('--src-mirror-url',
                        metavar='MIRROR_URL',
                        type=str,
                        help="URL of the source mirror")
    dest = sync.add_mutually_exclusive_group(required=True)
    dest.add_argument('--dest-directory',
                      metavar='DIRECTORY',
                      type=str,
                      help="Destination mirror as a local file path")
    dest.add_argument('--dest-mirror-name',
                      metavar='MIRROR_NAME',
                      type=str,
                      help="Name of the destination mirror")
    dest.add_argument('--dest-mirror-url',
                      metavar='MIRROR_URL',
                      type=str,
                      help="URL of the destination mirror")
    sync.set_defaults(func=sync_fn)

    # Update buildcache index without copying any additional packages
    update_index = subparsers.add_parser(
        'update-index', help=update_index_fn.__doc__)
    update_index.add_argument(
        '-d', '--mirror-url', default=None, help='Destination mirror url')
    update_index.add_argument(
        '-k', '--keys', default=False, action='store_true',
        help='If provided, key index will be updated as well as package index')
    update_index.set_defaults(func=update_index_fn)