Exemple #1
0
def main():
    _add_project_modules_to_sys_path()

    commands = Group(no_args_is_help=True)
    for command in SUPPORTED_COMMANDS:
        commands.add_command(command, command.name)
    click.CommandCollection(sources=[commands])()
Exemple #2
0
def make(cli: click.Group):
    @cli.command(name="search")
    @click.argument("query", type=click.STRING)
    @click.pass_obj
    def search(ctx, query):
        ctx = config.getctx(ctx)
        r = ctx.session.get(
            "search",
            params={"q": query},
        )
        if not r.ok:
            exit_with(handle_request_error(r))
        for result in r.json()["hits"]["hits"]:
            click.secho(
                f'{result["_source"]["owner_name"]}/', fg="cyan", bold=True, nl=False
            )
            click.secho(
                f'{result["_source"]["workspace_name"]}',
                fg="cyan",
                bold=True,
                nl=False,
            )
            click.secho(result["_source"]["path"])

    cli.add_command(search)
Exemple #3
0
def _get_nested_command(grp: Group, names: Iterable[str]) -> Union[Group, Command]:
    """Recursively find nested command and get it's help."""
    if len(names) == 1:
        return grp.get_command(Context(grp, info_name=grp.name), names[0])
    else:
        child_grp = grp.get_command(Context(grp, info_name=grp.name), names[0])
        return _get_nested_command(child_grp, names[1:])
Exemple #4
0
def make(cli: click.Group):
    @click.command(name="login")
    @click.option("--access-key", prompt=True)
    @click.option("--secret-key", prompt=True)
    @click.pass_obj
    def login(ctx, access_key, secret_key):
        ctx = config.getctx(ctx)
        r = ctx.session.get("user/me", auth=(access_key, secret_key))
        if r.ok:
            click.echo(click.style("Login success", fg="green", bold=True))
            ctx.config.access_key = access_key
            ctx.config.secret_key = secret_key
            config.save(ctx)
        else:
            exit_with(handle_request_error(r))

    @click.command(name="info")
    @click.pass_obj
    def me(ctx):
        ctx = config.getctx(ctx)
        r1 = ctx.session.get("user/me")
        if not r1.ok:
            exit_with(handle_request_error(r1))
        out = r1.json()
        out.update(ctx.config.dict())
        out.update({"configPath": ctx.configPath})
        exit_with(out)

    cli.add_command(login)
    cli.add_command(me)
Exemple #5
0
    def register_to(self, group: click.Group) -> None:
        """
        Registers all commands to the given group.

        :param group: Click group to register the commands to
        """
        for command in self.commands:
            group.add_command(command)
 def get_command(self, ctx: Context, cmd_name: str) -> Optional[Command]:
     rv = Group.get_command(self, ctx, cmd_name)
     if rv:
         return rv
     dashed = cmd_name.replace("_", "-")
     for cmd in self.list_commands(ctx):
         if cmd == dashed:
             return Group.get_command(self, ctx, cmd)
     return None
Exemple #7
0
def add_plugin_commands(command_group: click.Group) -> None:
    """
    Add commands provided by all plugins to the given command group. Each command is
    added with a name that is equal to the plugin name.
    """
    for plugin in plugins.iter_installed():
        if isinstance(plugin.command, click.Command):
            plugin.command.name = plugin.name
            command_group.add_command(plugin.command)
Exemple #8
0
def maybe_add_run_to_cli(cli: click.Group) -> None:
    if "run" not in cli.commands:
        if state.file or state.module:
            obj = get_typer_from_state()
            if obj:
                obj._add_completion = False
                click_obj = typer.main.get_command(obj)
                click_obj.name = "run"
                if not click_obj.help:
                    click_obj.help = "Run the provided Typer app."
                cli.add_command(click_obj)
Exemple #9
0
 def get_command(self, ctx, cmd_name):
     rv = Group.get_command(self, ctx, cmd_name)
     if rv is not None:
         return rv
     matches = [
         x for x in self.list_commands(ctx) if x.startswith(cmd_name)
     ]
     if not matches:
         return None
     elif len(matches) == 1:
         return Group.get_command(self, ctx, matches[0])
     ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
Exemple #10
0
def make(cli: click.Group):
    @cli.group(name="token", cls=ClickAliasedGroup, aliases=["t"])
    def token():
        pass

    @token.command(name="fetch", aliases=["f"])
    @click.argument("workspaces", type=click.STRING, nargs=-1)
    @click.pass_obj
    def create_token(ctx, workspaces):
        if len(workspaces) == 0:
            return
        r = ctx["session"].post("token/search",
                                json={"search_terms": workspaces})
        if r.ok:
            response = schemas.S3TokenSearchResponse(**r.json())
            for wrapper in response.tokens:
                node = wrapper.node
                token = wrapper.token
                click.secho(
                    f"Credentials for {[w.name for w in token.workspaces]} @ {node.api_url}",
                    fg="green",
                )
                click.secho(
                    f"Expires in {token.expiration - datetime.utcnow()}\n",
                    fg="yellow")
                click.secho(f"export AWS_ACCESS_KEY_ID={token.access_key_id}")
                click.secho(
                    f"export AWS_SECRET_ACCESS_KEY={token.secret_access_key}")
                click.secho(
                    f"export AWS_SESSION_TOKEN={token.session_token}\n")
        else:
            exit_with(handle_request_error(r))

    @token.command(name="list", aliases=["l", "ls"])
    @click.pass_obj
    def list_token(ctx):
        r = ctx["session"].get("token")
        exit_with(handle_request_error(r))

    @token.command(name="delete", aliases=["d"])
    @click.option("--all", is_flag=True)
    @click.argument("token_id", required=False)
    @click.pass_obj
    def delete_token(ctx, all, token_id):
        if all:
            r = ctx["session"].delete("token")
        else:
            r = ctx["session"].delete(f"token/{token_id}")
        exit_with(handle_request_error(r))

    cli.add_command(token)
Exemple #11
0
    def add_command(self, cmd, name=None):
        """ Hook the added command and put the group options on the command """
        Group.add_command(self, cmd, name=name)

        cmd.require_project = '@@ignore_check@@' not in (cmd.callback.__doc__
                                                         or "")

        # add the group parameters to the command
        for param in self.params:
            cmd.params.append(param)

        # hook the command's invoke with our own
        cmd.invoke = self.build_command_invoke(cmd.invoke)
        self.invoke_without_command = True
Exemple #12
0
def generate_reference(cli: Group):
    with cli.make_context("tokfetch", ["tokfetch"], max_content_width=200, terminal_width=200) as ctx:
        main_help = cli.get_help(ctx)
        main_help = remove_ansi(main_help)
        main_help = textwrap.indent(main_help, "   ")
        print(TEMPLATE.format(main_help))

        for name in sorted(cli.commands.keys()):
            cmd = cli.commands[name]
            with cli.make_context("tokfetch {}".format(name), ["tokfetch", name]) as subcommand_ctx:
                short_help = cmd.help
                long_help = cmd.get_help(subcommand_ctx)
                long_help = textwrap.indent(long_help, "    ")
                print(SUBCOMMAND_TEMPLATE.format(name, name, short_help, long_help))
Exemple #13
0
def make(cli: click.Group):
    @cli.group(name="index")
    def index():
        pass

    @index.command(name="delete")
    @click.argument("root_id", type=click.STRING)
    @click.pass_obj
    def delete(ctx, root_id):
        r = config.getctx(ctx).session.delete(f"root/{root_id}/index")
        exit_with(handle_request_error(r))

    @index.command(name="create")
    @click.argument("root_id", type=click.STRING)
    @click.pass_obj
    def create(ctx, root_id):
        ctx = config.getctx(ctx)
        r = ctx.session.post(f"root/{root_id}/index")
        r2 = ctx.session.get("info")
        if r.ok and r2.ok:
            data = r.json()
            infodata = r2.json()
            root_id = data["root_id"]
            bucket = data["root"]["bucket"]
            prefix = posixpath.join(data["root"]["base_path"], "/").lstrip("/")
            endpoint_base = infodata["public_address"]
            click.secho(
                "To notify Workspaces of updates, configure your MinIO instance using these commands.\n",
                fg="yellow",
            )
            for c in [
                    # wehook ID should come from ROOT, not index.  You only want to subscribe to events once.
                    f"export ALIAS=local",
                    f"mc admin config set $ALIAS notify_webhook:{root_id} endpoint={endpoint_base}/api/minio/events enable=on",
                    f"mc event add $ALIAS/{bucket} arn:minio:sqs::{root_id}:webhook {f'--prefix {prefix}' if prefix else ''} --event delete,put",
            ]:
                click.secho("\t" + c, fg="blue", bold=True)
            click.echo("")
        else:
            exit_with(handle_request_error(r))

    cli.add_command(index)
Exemple #14
0
def test_request_headers(scan_mock: Mock, client):
    c = Commit()
    c._patch = _SIMPLE_SECRET

    with Context(Command("bar"), info_name="bar") as ctx:
        ctx.parent = Context(Group("foo"), info_name="foo")
        c.scan(
            client=client,
            cache=Cache(),
            matches_ignore={},
            all_policies=True,
            verbose=False,
        )
    scan_mock.assert_called_with(
        ANY,
        {
            "GGShield-Version": __version__,
            "GGShield-Command-Path": "foo bar",
        },
    )
Exemple #15
0
def make(cli: click.Group):
    @click.command(name="login")
    @click.argument("email")
    @click.option("--password", prompt=True, hide_input=True)
    @click.pass_obj
    def login(ctx, email, password):
        conf = ctx["config"]
        r = ctx["session"].post(
            "auth/jwt/login",
            {
                "username": email,
                "password": password,
            },
        )
        if r.ok:
            token = r.json()["access_token"]
            click.echo(click.style("Login success", fg="green", bold=True))
            conf.token = token
            save_config(conf, ctx["configPath"])
        else:
            exit_with(handle_request_error(r))

    @click.command(name="register")
    @click.argument("email")
    @click.argument("username")
    @click.option("--password", prompt=True, hide_input=True)
    @click.pass_obj
    def register(ctx, email, password, username):
        r = ctx["session"].post(
            "auth/register",
            json={
                "email": email,
                "username": username,
                "password": password,
            },
        )
        exit_with(handle_request_error(r))

    @click.command(name="info")
    @click.pass_obj
    def me(ctx):
        r = ctx["session"].get("me")
        exit_with(handle_request_error(r))

    cli.add_command(login)
    cli.add_command(register)
    cli.add_command(me)
Exemple #16
0
def vdk_command_line(root_command: click.Group) -> None:
    root_command.add_command(ingest_csv)
Exemple #17
0
 def __init__(self, name=None, commands=[], **attrs):
     Group.__init__(self, name, **attrs)
     self.commands = OrderedDict(commands)
def add_commands(cli: click.Group) -> None:
    cli.add_command(print_model)
Exemple #19
0
import string
import random
import secrets

from click import Group, option

from back.models import helper

ALPHANUMERIC = string.ascii_letters + string.digits
MIN_PLACE_ID_LEN = 20
MAX_PLACE_ID_LEN = 256

db_cli = Group("db")


def generate_place_id():
    # See for information about Google place_id https://developers.google.com/places/web-service/place-id
    id_len = random.randint(MIN_PLACE_ID_LEN, MAX_PLACE_ID_LEN)
    return "".join(secrets.choice(ALPHANUMERIC) for _ in range(id_len))


@db_cli.command("fill")
@option("--likes", default=5, help="Number of likes")
@option("--dislikes", default=5, help="Number of dislikes")
def fill_db(likes, dislikes):
    user_data = dict(
        first_name="United",
        last_name="Remote",
        email="*****@*****.**",
        password="******"
    )
Exemple #20
0
def db_commands(group: click.Group) -> click.Group:
    group.add_command(create_all)
    group.add_command(drop_all)
    return group
Exemple #21
0
from click import Group

manager = Group(help="Manage the database (create/drop tables).")


@manager.command()
def create_tables():
    """Create the database tables."""
    from redash.models import create_db, init_db

    create_db(True, False)
    init_db()


@manager.command()
def drop_tables():
    """Drop the database tables."""
    from redash.models import create_db

    create_db(False, True)
Exemple #22
0
def invoke_tree(root: click.Group, subcommands: List[str]):
    click_ctx = click.get_current_context()
    click_ctx.args = subcommands[1:]
    click_ctx.protected_args = subcommands[:1]
    root.invoke(click_ctx)
Exemple #23
0
def register(cli: click.Group):
    cli.add_command(build)
    cli.add_command(clean)
    cli.add_command(pause)
    cli.add_command(print_tokens)
    cli.add_command(reset)
    cli.add_command(resume)
    cli.add_command(run_docker_command)
    cli.add_command(scale)
    cli.add_command(setup)
    cli.add_command(start)
    cli.add_command(validate)
    cli.add_command(worker)
 def register_to(self, group: click.Group) -> None:
     for command in self.commands:
         group.add_command(command)
Exemple #25
0
def add_commands(command_group: click.Group) -> None:
    command_group.add_command(start)
    command_group.add_command(stop)
    command_group.add_command(restart)
    command_group.add_command(reboot)
    command_group.add_command(init)
    command_group.add_command(createuser)
    command_group.add_command(importdemocourse)
    command_group.add_command(settheme)
    command_group.add_command(dc_command)
    command_group.add_command(run)
    command_group.add_command(copyfrom)
    command_group.add_command(bindmount_command)
    command_group.add_command(execute)
    command_group.add_command(logs)
    command_group.add_command(status)
Exemple #26
0
def make(cli: click.Group):
    @cli.group(name="root", cls=ClickAliasedGroup, aliases=["r"])
    def root():
        pass

    @root.command(name="list", aliases=["l", "ls"])
    @click.option("--node-name", type=click.STRING)
    @click.pass_obj
    def list_roots(ctx, node_name):
        r = ctx["session"].get("root", params={"node_name": node_name})
        exit_with(handle_request_error(r))

    @root.command(name="create", aliases=["c"])
    @click.argument("bucket", type=click.STRING)
    @click.argument("node_name", type=click.STRING)
    @click.option("--base-path", type=click.STRING, default="")
    @click.option(
        "--root-type",
        type=click.Choice(schemas.RootType),
        default=schemas.RootType.PRIVATE.value,
    )
    @click.pass_obj
    def create_root(ctx, bucket, node_name, base_path, root_type):
        r = ctx["session"].post(
            "root",
            json={
                "bucket": bucket,
                "node_name": node_name,
                "base_path": base_path,
                "root_type": root_type,
            },
        )
        exit_with(handle_request_error(r))

    @root.command(name="delete", aliases=["d"])
    @click.argument("root_id", type=click.STRING)
    @click.pass_obj
    def delete_root(ctx, root_id):
        r = ctx["session"].delete(f"root/{root_id}")
        exit_with(handle_request_error(r))

    @root.command(name="import", help="Import all workspaces in a root.")
    @click.argument("root_id")
    @click.option("--index-all", is_flag=True)
    @click.pass_obj
    def import_all_workspaces(ctx, root_id, index_all):
        # Dynamic, expensive imports
        from workspacesio.common import producers

        ctx = config.getctx(ctx)
        r = ctx.session.post(f"root/{root_id}/import")
        if not r.ok:
            exit_with(handle_request_error(r))
        rdata = schemas.RootCredentials(**r.json())
        root_contents = producers.minio_list_root_children(node=rdata.node,
                                                           root=rdata.root)
        workspace_list: List[schemas.WorkspaceDB] = []
        for folder in root_contents:
            prefix = folder.object_name.lstrip(rdata.root.base_path).strip("/")
            if len(prefix) > 0:
                print(f"Discovered {prefix}")
                workspace = ctx.session.post(
                    "workspace",
                    json={
                        "name": prefix,
                        "public": False,
                        "unmanaged": True,
                        "base_path": prefix,
                        "node_name": rdata.node.name,
                        "root_id": str(rdata.root.id),
                    },
                )
                if not workspace.ok and workspace.status_code != 409:
                    exit_with(handle_request_error(workspace))
                workspace_list.append(schemas.WorkspaceDB(**workspace.json()))

    @root.command(name="import-workspace",
                  help="Import a particular prefix as a workspace.")
    @click.argument("root_id", type=click.STRING)
    @click.argument("--base-path", type=click.STRING, default="")
    def import_workspace(ctx, root_id, base_path):
        pass

    cli.add_command(root)
Exemple #27
0
def pytask_extend_command_line_interface(cli: click.Group) -> None:
    """Extend the command line interface."""
    cli.add_command(clean)
Exemple #28
0
    def __init__(
        self,
        cli: click.Group,
        pipeline_func: Callable,
        services: PlatformServicesBase,
        image_url: str,
        package_entrypoint: str,
        op_builders: List[Callable[[HmlContainerOp], HmlContainerOp]],
        envs: Dict[str, str],
    ):

        if cli is None:
            raise (TypeError("Parameter: `cli` must be supplied"))
        if pipeline_func is None:
            raise (TypeError("Parameter: `pipeline_func` must be supplied"))
        if services is None:
            raise (TypeError("Parameter: `services` must be supplied"))
        if image_url is None or image_url == "":
            raise (TypeError("Parameter: `image_url` must be supplied"))
        if package_entrypoint is None or package_entrypoint == "":
            raise (
                TypeError("Parameter: `package_entrypoint` must be supplied"))

        self.name = pipeline_func.__name__
        self.envs: Dict[str, str] = envs
        self.services = services
        self.pipeline_func = pipeline_func
        self.kubeflow_pipeline = dsl.pipeline(pipeline_func,
                                              pipeline_func.__name__)

        self.is_deploying = False

        self.cron: Optional[str] = None
        self.experiment: Optional[str] = None

        self.image_url = image_url
        self.package_entrypoint = package_entrypoint

        # The methods we use to configure our Ops for running in Kubeflow
        self.op_builders = op_builders

        self.ops_list: List[HmlContainerOp] = []
        self.ops_dict: Dict[str, HmlContainerOp] = {}

        # We treat the pipeline as a "group" of commands, rather than actually executing
        # anything.  We can then bind a
        self.cli_pipeline = click.group(name=pipeline_func.__name__)(_pass)

        # Register this with the root `pipeline` command
        cli.add_command(self.cli_pipeline)

        # Create a command to execute the whole pipeline
        self.cli_all = click.command(name="run-all")(self.run_all)

        self.deploy_dev = self._apply_deploy_options(
            click.command(name="deploy-dev")(self._deploy_dev))
        self.deploy_prod = self._apply_deploy_options(
            click.command(name="deploy-prod")(self._deploy_prod))

        self.cli_pipeline.add_command(self.cli_all)
        self.cli_pipeline.add_command(self.deploy_dev)
        self.cli_pipeline.add_command(self.deploy_prod)
Exemple #29
0
from sys import exit

from click import Group, argument, option
from redash import models

manager = Group(help="Groups management commands.")


@manager.command()
@argument('name')
@option('--org', 'organization', default='default',
        help="The organization the user belongs to (leave blank for "
        "'default').")
@option('--permissions', default=None,
        help="Comma separated list of permissions ('create_dashboard',"
        " 'create_query', 'edit_dashboard', 'edit_query', "
        "'view_query', 'view_source', 'execute_query', 'list_users',"
        " 'schedule_query', 'list_dashboards', 'list_alerts',"
        " 'list_data_sources') (leave blank for default).")
def create(name, permissions=None, organization='default'):
    print "Creating group (%s)..." % (name)

    org = models.Organization.get_by_slug(organization)

    permissions = extract_permissions_string(permissions)

    print "permissions: [%s]" % ",".join(permissions)

    try:
        models.Group.create(name=name, org=org, permissions=permissions)
    except Exception, e:
Exemple #30
0
from click import Group
from cli.start import start
from cli.stop import stop
from cli.logs import logs
from cli.build import build
from cli.kill import kill

cli = Group()
cli.add_command(start)
cli.add_command(stop)
cli.add_command(logs)
cli.add_command(build)
cli.add_command(kill)
Exemple #31
0
from os import environ
from click import Group, option, echo, secho, style
from pathlib import Path
from sparrow import Database

from .et_redux_importer import ETReduxImporter
from .import_metadata import import_metadata

cli = Group()


@cli.command(name="import-xml")
@option("--fix-errors", is_flag=True, default=False)
@option("--redo", is_flag=True, default=False)
def import_xml(**kwargs):
    """
    Import Boise State XML files
    """
    varname = "SPARROW_DATA_DIR"
    env = environ.get(varname, None)
    if env is None:
        v = style(varname, fg="cyan", bold=True)
        echo(f"Environment variable {v} is not set.")
        secho("Aborting", fg="red", bold=True)
        return
    path = Path(env)
    assert path.is_dir()

    db = Database()
    importer = ETReduxImporter(db)
    files = path.glob("**/*.xml")