예제 #1
0
import click
from click_option_group import optgroup  # type: ignore
from click_skeleton import add_options

from musicbot.cli.options import sane_list
from musicbot.defaults import (DEFAULT_MAX_RATING, DEFAULT_MIN_RATING,
                               DEFAULT_RATINGS)

bests_options = add_options(
    optgroup.group("Bests options"),
    optgroup.option('--min-playlist-size',
                    help="Minimum size of playlist to write",
                    default=1),
    optgroup.option(
        '--rating',
        'ratings',
        help="Generate bests for those ratings",
        default=DEFAULT_RATINGS,
        type=click.FloatRange(DEFAULT_MIN_RATING,
                              DEFAULT_MAX_RATING,
                              clamp=True),
        multiple=True,
    ),
    optgroup.option('--types',
                    help="Type of bests playlists",
                    default=["genre", "keyword", "rating", "artist"],
                    multiple=True,
                    callback=sane_list),
)
예제 #2
0
import click
from click_option_group import optgroup  # type: ignore
from click_skeleton import add_options

from musicbot.cli.options import config_string
from musicbot.musicdb import MusicDb


def sane_musicdb(ctx: click.Context, param: click.Parameter, value: str) -> MusicDb:
    if param.name:
        ctx.params[param.name] = value
    dsn = ctx.params.pop('dsn')
    musicdb = MusicDb.from_dsn(dsn)
    ctx.params['musicdb'] = musicdb
    return musicdb


musicdb_options = add_options(
    optgroup('MusicDB options'),
    optgroup.option(
        '--dsn',
        help='DSN to MusicBot EdgeDB',
        callback=config_string,
    ),
    optgroup.option(
        '--musicdb',
        expose_value=False,
        callback=sane_musicdb,
    ),
)
예제 #3
0
link_options_options = add_options(
    optgroup('Link options'),
    optgroup.option(
        '--http/--no-http',
        help="Generate HTTP link",
        is_flag=True,
        default=DEFAULT_HTTP,
        show_default=True,
    ),
    optgroup.option(
        '--sftp/--no-sftp',
        help="Generate sFTP link",
        is_flag=True,
        default=DEFAULT_SFTP,
        show_default=True,
    ),
    # optgroup.option(
    #     '--youtube/--no-youtube',
    #     help="Generate YouTube link",
    #     is_flag=True,
    #     default=DEFAULT_YOUTUBE,
    #     show_default=True,
    # ),
    # optgroup.option(
    #     '--spotify/--no-spotify',
    #     help="Generate Spotify link",
    #     is_flag=True,
    #     default=DEFAULT_SPOTIFY,
    #     show_default=True,
    # ),
    optgroup.option(
        '--local/--no-local',
        help="Generate local link",
        is_flag=True,
        default=DEFAULT_LOCAL,
        show_default=True,
    ),
    optgroup.option(
        '--link-options',
        help="Link options",
        expose_value=False,
        hidden=True,
        callback=sane_link_options
    ),
)
예제 #4
0
    nargs=-1,
    callback=sane_set,
)

flat_option = click.option(
    '--flat',
    help="Do not create subfolders",
    is_flag=True,
    default=DEFAULT_FLAT,
)

file_options = add_options(
    music_options_group,
    keywords_option,
    artist_option,
    album_option,
    title_option,
    genre_option,
    track_option,
    rating_option,
)


@beartype
def sane_file(ctx: click.Context, param: click.Parameter, value: Path) -> File:
    if not param.name:
        logger.error("no param name set")
        raise click.Abort()
    file = File.from_path(value)
    ctx.params[param.name] = file
    return file
예제 #5
0
    callback=config_string,
)

spotify_client_secret_option = optgroup.option(
    '--spotify-client-secret',
    help='Spotify client secret',
    envvar='MB_SPOTIFY_CLIENT_SECRET',
    default=DEFAULT_SPOTIFY_CLIENT_SECRET,
    callback=config_string,
)

spotify_token_option = optgroup.option(
    '--spotify-token',
    help='Spotify token',
    envvar='MB_SPOTIFY_TOKEN',
    expose_value=False,
    default=DEFAULT_SPOTIFY_TOKEN,
    callback=sane_spotify,
)

spotify_options = add_options(
    optgroup('Spotify options'),
    spotify_username_option,
    spotify_client_id_option,
    spotify_client_secret_option,
    spotify_cache_path_option,
    spotify_scope_option,
    spotify_redirect_uri_option,
    spotify_token_option,
)
예제 #6
0
import logging
from typing import Any

import click

import examples.commands
from click_skeleton import add_options, doc, skeleton

PROG_NAME = 'example-cli'
__version__ = '1.0.0'
logger = logging.getLogger(PROG_NAME)

global_example_option = click.option('--global-example',
                                     help="A global option")
group_of_options = add_options(
    click.option('--option-one', help="First option"),
    click.option('--option-two', help="Second option"),
)


@skeleton(name=PROG_NAME, version=__version__, auto_envvar_prefix='CLI')
@click.pass_context
@global_example_option
@group_of_options
def main_cli(ctx: click.Context, global_example: str, option_one: str,
             option_two: str) -> Any:
    """Simple CLI example"""
    logger.info(f"in main_cli: ctx = {ctx}")
    logger.info(f"in main_cli: global_example = {global_example}")
    logger.info(f"in main_cli: option_one = {option_one}")
    logger.info(f"in main_cli: option_two = {option_two}")
    ctx.obj.global_option = global_example
예제 #7
0
                                     path_type=Path,
                                     exists=True,
                                     file_okay=False,
                                 ))

folders_argument = add_options(
    dry_option, optgroup.group("Folders options"),
    optgroup.option(
        '--limit',
        help="Limit number of music files",
        type=int,
        is_eager=True,
    ),
    optgroup.option(
        '--extension',
        'extensions',
        help='Supported formats',
        default=sorted(DEFAULT_EXTENSIONS),
        multiple=True,
        callback=split_arguments,
        show_default=True,
        is_eager=True,
    ), click.argument(
        'folders',
        nargs=-1,
        callback=sane_folders,
    ))

destination_argument = click.argument(
    'destination',
    type=click.Path(
        path_type=Path,
예제 #8
0
critical_option = optgroup.option(
    '--critical',
    help='Critical verbosity',
    envvar='MB_CRITICAL',
    default=DEFAULT_CRITICAL,
    is_flag=True,
)

quiet_option = optgroup.option(
    '-q', '--quiet/--no-quiet',
    help='Disable progress bars',
    envvar='MB_QUIET',
    default=DEFAULT_QUIET,
    is_flag=True,
    show_default=True,
)

config_options = add_options(
    optgroup('Global options'),
    config_option,
    log_option,
    quiet_option,
    color_option,
    optgroup('Verbosity', cls=MutuallyExclusiveOptionGroup),
    debug_option,
    info_option,
    warning_option,
    error_option,
    critical_option,
)
예제 #9
0
shuffle_option = optgroup.option(
    '--shuffle',
    help='Randomize selection',
    default=DEFAULT_SHUFFLE,
    is_flag=True,
)

interleave_option = optgroup.option(
    '--interleave',
    help='Interleave tracks by artist',
    is_flag=True,
)

ordering_options = add_options(
    optgroup('Ordering options'),
    shuffle_option,
    interleave_option,
)

music_filter_options = add_options(
    optgroup('Filter options'),
    optgroup.option(
        '--name',
        help='Filter name',
        default=DEFAULT_NAME,
    ),
    optgroup.option(
        '--limit',
        help='Fetch a maximum limit of music',
        default=DEFAULT_LIMIT,
    ),