示例#1
0
def connection(
    ctx: typer.Context,
    username: str = typer.Option(
        ...,
        prompt=True,
        envvar="HI_USERNAME",
        help=
        'Username without "@hi.is". If the environment variable does not exist you will be prompted.',
    ),
    password: str = typer.Option(
        ...,
        prompt=True,
        hide_input=True,
        envvar="HI_PASSWORD",
        help="If the environment variable does not exist you will be prompted.",
    ),
    host: SFTPHosts = typer.Option(SFTPHosts.krafla,
                                   help="sftp remote hostname"),
):
    """
    Create sftp connection
    """
    sftp, _ = get_connection(host, username, password)
    ctx.ensure_object(dict)
    ctx.obj["sftp"] = sftp
示例#2
0
def openapi_main(
    ctx: typer.Context,
    token: str = typer.Option('', envvar='TINVEST_TOKEN'),  # noqa:B008
    sandbox_token: str = typer.Option('', envvar='TINVEST_SANDBOX_TOKEN'),  # noqa:B008
    use_sandbox: bool = typer.Option(False, '--use-sandbox', '-s'),  # noqa:B008
):
    ctx.ensure_object(OpenapiCtx)
    ctx.obj.token = token
    ctx.obj.sandbox_token = sandbox_token
    ctx.obj.use_sandbox = use_sandbox
示例#3
0
def hamming(
    ctx: typer.Context,
    verbose: bool = typer.Option(False, "-v", "--verbose", help="Verbose output"),
):
    """Top-level entrypoint into hamming-codec commandline utilities"""

    if ctx.invoked_subcommand is None:
        print("No subcommand specified")
        sys.exit(1)

    # ensure that ctx.obj exists and is a dict
    ctx.ensure_object(dict)

    # pass the verbose flag to the sub-commands
    ctx.obj["VERBOSE"] = verbose
示例#4
0
def main(
    ctx: typer.Context,
    cfg: Path = typer.Option(DEFAULT_PROJECT_CONFIG,
                             "--config",
                             "-c",
                             help="Set the configuration file."),
    repository: str = typer.Option(
        DEFAULT_REPOSITORY,
        help="Set the remote repository. Required format: owner/repository.",
    ),
    token: str = typer.Option(DEFAULT_GITHUB_TOKEN,
                              help="Set github access token."),
    log_level: LoggingChoices = typer.Option(DEFAULT_LOG_LEVEL,
                                             help="Set logging level."),
):
    """
    Hammurabi is an extensible CLI tool responsible for enforcing user-defined rules on a git
    repository.

    Find more information at: https://hammurabi.readthedocs.io/latest/
    """

    if ctx.invoked_subcommand in NON_ACTIONABLE_SUBCOMMANDS:
        return

    os.environ.setdefault("HAMMURABI_SETTINGS_PATH", str(cfg.expanduser()))

    try:
        # Reload the configuration
        config.load()
        success_message("Configuration loaded")
    except Exception as exc:  # pylint: disable=broad-except
        error_message(f"Failed to load configuration: {str(exc)}")
        return

    if token != DEFAULT_GITHUB_TOKEN:
        config.github = github3.login(token=token)

    if repository != DEFAULT_REPOSITORY:
        config.settings.repository = repository

    if log_level != DEFAULT_LOG_LEVEL:
        logging.root.setLevel(log_level.value)

    ctx.ensure_object(dict)
    ctx.obj["config"] = config
示例#5
0
async def cli(ctx: Context, config: str = typer.Option("aerich.ini", "--config", "-c", help="Config file.", ),
              app: str = typer.Option(None, help="Tortoise-ORM app name."),
              name: str = typer.Option("aerich", "--name", "-n",
                                       help="Name of section in .ini file to use for aerich config.", )):
    ctx.ensure_object(dict)
    ctx.obj["config_file"] = config
    ctx.obj["name"] = name
    invoked_subcommand = ctx.invoked_subcommand
    sys.path.insert(0, ".")
    if invoked_subcommand != "init":
        if not os.path.exists(config):
            typer.secho("You must exec init first", )
            raise typer.Exit()
        parser.read(config)
        location = parser[name]["location"]
        tortoise_orm = parser[name]["tortoise_orm"]
        tortoise_config = get_tortoise_config(ctx, tortoise_orm)
        app = app or list(tortoise_config.get("apps").keys())[0]
        if "aerich.models" not in tortoise_config.get("apps").get(app).get("models"):
            typer.secho("Check your tortoise config and add aerich.models to it.")
            raise typer.Exit()
        ctx.obj["config"] = tortoise_config
        ctx.obj["location"] = location
        ctx.obj["app"] = app