Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(client): add aliases for swcli commands #1388

Merged
merged 6 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
client-check-all:
cd client && $(MAKE) all-check
bash scripts/run_demo.sh
11 changes: 6 additions & 5 deletions client/starwhale/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import click

from starwhale.version import STARWHALE_VERSION
from starwhale.utils.cli import AliasedGroup
from starwhale.utils.debug import init_logger
from starwhale.utils.config import load_swcli_config
from starwhale.core.eval.cli import eval_job_cmd
Expand All @@ -19,7 +20,7 @@


def create_sw_cli() -> click.core.Group:
@click.group()
@click.group(cls=AliasedGroup)
@click.version_option(version=STARWHALE_VERSION)
@click.option(
"-v",
Expand All @@ -38,11 +39,11 @@ def cli(ctx: click.Context, verbose: bool, output: str) -> None:
random.seed(time.time_ns())

cli.add_command(instance_cmd)
cli.add_command(project_cmd)
cli.add_command(project_cmd, aliases=["prj"]) # type: ignore
cli.add_command(eval_job_cmd)
cli.add_command(runtime_cmd)
cli.add_command(model_cmd)
cli.add_command(dataset_cmd)
cli.add_command(runtime_cmd, aliases=["rt"]) # type: ignore
cli.add_command(model_cmd, aliases=["mp"]) # type: ignore
cli.add_command(dataset_cmd, aliases=["ds"]) # type: ignore
cli.add_command(open_board)
cli.add_command(completion_cmd)
add_mngt_command(cli)
Expand Down
5 changes: 4 additions & 1 deletion client/starwhale/cli/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from starwhale.utils import console, get_current_shell
from starwhale.utils.fs import ensure_dir
from starwhale.utils.cli import AliasedGroup

_SUPPORT_SHELLS = {
"bash": ("~/.bashrc", 'eval "$(_{prog_u}_COMPLETE=bash_source {prog})"'),
Expand All @@ -16,7 +17,9 @@
}


@click.group("completion", help="Shell completion for Starwhale command-line")
@click.group(
"completion", cls=AliasedGroup, help="Shell completion for Starwhale command-line"
)
def completion_cmd() -> None:
pass

Expand Down
13 changes: 9 additions & 4 deletions client/starwhale/core/dataset/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
)
from starwhale.base.uri import URI
from starwhale.base.type import URIType
from starwhale.utils.cli import AliasedGroup

from .view import get_term_view, DatasetTermView


@click.group("dataset", help="Dataset management, build/info/list/copy/tag...")
@click.group(
"dataset",
cls=AliasedGroup,
help="Dataset management, build/info/list/copy/tag...",
)
@click.pass_context
def dataset_cmd(ctx: click.Context) -> None:
ctx.obj = get_term_view(ctx.obj)
Expand Down Expand Up @@ -61,7 +66,7 @@ def _diff(
view(base_uri).diff(URI(compare_uri, expected_type=URIType.DATASET), show_details)


@dataset_cmd.command("list", help="List dataset")
@dataset_cmd.command("list", aliases=["ls"], help="List dataset")
@click.option("-p", "--project", default="", help="Project URI")
@click.option("--fullname", is_flag=True, help="Show fullname of dataset version")
@click.option("--show-removed", is_flag=True, help="Show removed datasets")
Expand Down Expand Up @@ -92,7 +97,7 @@ def _info(view: t.Type[DatasetTermView], dataset: str, fullname: bool) -> None:
view(dataset).info(fullname)


@dataset_cmd.command("remove")
@dataset_cmd.command("remove", aliases=["rm"])
@click.argument("dataset")
@click.option(
"-f",
Expand Down Expand Up @@ -143,7 +148,7 @@ def _summary(view: t.Type[DatasetTermView], dataset: str) -> None:
view(dataset).summary()


@dataset_cmd.command("copy", help="Copy dataset, standalone <--> cloud")
@dataset_cmd.command("copy", aliases=["cp"], help="Copy dataset, standalone <--> cloud")
@click.argument("src")
@click.argument("dest")
@click.option("-f", "--force", is_flag=True, help="Force copy dataset")
Expand Down
13 changes: 9 additions & 4 deletions client/starwhale/core/eval/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

import click

from starwhale.utils.cli import AliasedGroup
from starwhale.consts.env import SWEnv

from .view import JobTermView, get_term_view, DEFAULT_PAGE_IDX, DEFAULT_PAGE_SIZE


@click.group(
"eval", help="Evaluation management, create/list/info/compare evaluation job"
"eval",
cls=AliasedGroup,
help="Evaluation management, create/list/info/compare evaluation job",
)
@click.pass_context
def eval_job_cmd(ctx: click.Context) -> None:
ctx.obj = get_term_view(ctx.obj)


@eval_job_cmd.command("list", help="List all jobs in the current project")
@eval_job_cmd.command(
"list", aliases=["ls"], help="List all jobs in the current project"
)
@click.option("-p", "--project", default="", help="Project URI")
@click.option("--fullname", is_flag=True, help="Show fullname of swmp version")
@click.option("--show-removed", is_flag=True, help="Show removed dataset")
Expand Down Expand Up @@ -108,7 +113,7 @@ def _run(
)


@eval_job_cmd.command("remove", help="Remove job")
@eval_job_cmd.command("remove", aliases=["rm"], help="Remove job")
@click.argument("job")
@click.option(
"-f",
Expand Down Expand Up @@ -164,7 +169,7 @@ def _info(view: t.Type[JobTermView], job: str, page: int, size: int) -> None:
view(job).info(page, size)


@eval_job_cmd.command("compare")
@eval_job_cmd.command("compare", aliases=["cmp"])
@click.argument("base_job", nargs=1)
@click.argument("job", nargs=-1)
def _compare(base_job: str, job: t.List[str]) -> None:
Expand Down
7 changes: 5 additions & 2 deletions client/starwhale/core/instance/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@

import click

from starwhale.utils.cli import AliasedGroup

from .view import get_term_view, InstanceTermView


@click.group(
"instance",
cls=AliasedGroup,
help="Starwhale Instance management, login and select standalone or cloud instance",
)
@click.pass_context
def instance_cmd(ctx: click.Context) -> None:
ctx.obj = get_term_view(ctx.obj)


@instance_cmd.command("select")
@instance_cmd.command("select", aliases=["use"])
@click.argument("instance")
def _select(instance: str) -> None:
"""
Expand Down Expand Up @@ -62,7 +65,7 @@ def _logout(instance: str) -> None:
InstanceTermView().logout(instance)


@instance_cmd.command("list", help="List login Starwhale instances")
@instance_cmd.command("list", aliases=["ls"], help="List login Starwhale instances")
@click.pass_obj
def _list(view: t.Type[InstanceTermView]) -> None:
view().list()
Expand Down
13 changes: 9 additions & 4 deletions client/starwhale/core/model/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import click

from starwhale.consts import DefaultYAMLName, DEFAULT_PAGE_IDX, DEFAULT_PAGE_SIZE
from starwhale.utils.cli import AliasedGroup
from starwhale.consts.env import SWEnv
from starwhale.core.model.view import get_term_view, ModelTermView


@click.group("model", help="Model management, build/copy/ppl/cmp/eval/extract...")
@click.group(
"model",
cls=AliasedGroup,
help="Model management, build/copy/ppl/cmp/eval/extract...",
)
@click.pass_context
def model_cmd(ctx: click.Context) -> None:
ctx.obj = get_term_view(ctx.obj)
Expand Down Expand Up @@ -41,7 +46,7 @@ def _tag(model: str, tags: t.List[str], remove: bool, quiet: bool) -> None:
ModelTermView(model).tag(tags, remove, quiet)


@model_cmd.command("copy", help="Copy model, standalone <--> cloud")
@model_cmd.command("copy", aliases=["cp"], help="Copy model, standalone <--> cloud")
@click.argument("src")
@click.argument("dest")
@click.option("-f", "--force", is_flag=True, help="Force to copy model")
Expand All @@ -57,7 +62,7 @@ def _info(view: t.Type[ModelTermView], model: str, fullname: bool) -> None:
view(model).info(fullname)


@model_cmd.command("list", help="List Model")
@model_cmd.command("list", aliases=["ls"], help="List Model")
@click.option("--project", default="", help="Project URI")
@click.option("--fullname", is_flag=True, help="Show fullname of model version")
@click.option("--show-removed", is_flag=True, help="Show removed model")
Expand Down Expand Up @@ -87,7 +92,7 @@ def _history(view: t.Type[ModelTermView], model: str, fullname: bool) -> None:
view(model).history(fullname)


@model_cmd.command("remove", help="Remove model")
@model_cmd.command("remove", aliases=["rm"], help="Remove model")
@click.argument("model")
@click.option(
"-f",
Expand Down
22 changes: 17 additions & 5 deletions client/starwhale/core/project/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

import click

from starwhale.utils.cli import AliasedGroup

from .view import get_term_view, ProjectTermView, DEFAULT_PAGE_IDX, DEFAULT_PAGE_SIZE


@click.group("project", help="Project management, for standalone and cloud instances")
@click.group(
"project",
cls=AliasedGroup,
help="Project management, for standalone and cloud instances",
)
@click.pass_context
def project_cmd(ctx: click.Context) -> None:
ctx.obj = get_term_view(ctx.obj)


@project_cmd.command("list", help="List projects in current Starwhale Instance")
@project_cmd.command(
"list", aliases=["ls"], help="List projects in current Starwhale Instance"
)
@click.option("-i", "--instance", default="", help="instance uri")
@click.option(
"--page",
Expand All @@ -31,20 +39,24 @@ def _list(view: t.Type[ProjectTermView], instance: str, page: int, size: int) ->


@project_cmd.command(
"create", help="Create a new project in current Starwhale instance"
"create",
aliases=["new", "add"],
help="Create a new project in current Starwhale instance",
)
@click.argument("project", type=str)
def _create(project: str) -> None:
ProjectTermView(project).create()


@project_cmd.command("select", help="Select default project in current instance")
@project_cmd.command(
"select", aliases=["use"], help="Select default project in current instance"
)
@click.argument("project", type=str)
def _select(project: str) -> None:
ProjectTermView(project).select()


@project_cmd.command("remove", help="Remove project")
@project_cmd.command("remove", aliases=["rm"], help="Remove project")
@click.argument("project", type=str)
def _remove(project: str) -> None:
ProjectTermView(project).remove()
Expand Down
22 changes: 15 additions & 7 deletions client/starwhale/core/runtime/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,32 @@
)
from starwhale.base.uri import URI
from starwhale.base.type import URIType, RuntimeLockFileType
from starwhale.utils.cli import AliasedGroup
from starwhale.utils.error import MissingFieldError, ExclusiveArgsError

from .view import get_term_view, RuntimeTermView


@click.group(
"runtime", help="Runtime management, quickstart/build/copy/activate/restore..."
"runtime",
cls=AliasedGroup,
help="Runtime management, quickstart/build/copy/activate/restore...",
)
@click.pass_context
def runtime_cmd(ctx: click.Context) -> None:
ctx.obj = get_term_view(ctx.obj)


@click.group("quickstart", help="[Standalone]Quickstart your Starwhale Runtime")
@click.group(
"quickstart",
cls=AliasedGroup,
help="[Standalone]Quickstart your Starwhale Runtime",
)
def quickstart() -> None:
pass


runtime_cmd.add_command(quickstart)
runtime_cmd.add_command(quickstart, aliases=["qs"]) # type: ignore


@quickstart.command("uri")
Expand Down Expand Up @@ -163,7 +170,7 @@ def _build(
)


@runtime_cmd.command("remove")
@runtime_cmd.command("remove", aliases=["rm"])
@click.argument("runtime")
@click.option(
"-f",
Expand Down Expand Up @@ -217,12 +224,12 @@ def _restore(target: str) -> None:
"""
[Only Standalone]Prepare dirs, restore python environment with virtualenv or conda and show activate command.

TARGET: runtime uri or runtime workdir path, in Starwhale Agent Docker Environment, only support workdir path.
TARGET: runtime uri or runtice workdir path, in Starwhale Agent Docker Environment, only support workdir path.
"""
RuntimeTermView.restore(target)


@runtime_cmd.command("list", help="List runtime")
@runtime_cmd.command("list", aliases=["ls"], help="List runtime")
@click.option("--project", default="", help="Project URI")
@click.option("--fullname", is_flag=True, help="Show fullname of runtime version")
@click.option("--show-removed", is_flag=True, help="Show removed runtime")
Expand Down Expand Up @@ -258,7 +265,7 @@ def _extract(runtime: str, force: bool, target_dir: str) -> None:
RuntimeTermView(runtime).extract(force, target_dir)


@runtime_cmd.command("copy", help="Copy runtime, standalone <--> cloud")
@runtime_cmd.command("copy", aliases=["cp"], help="Copy runtime, standalone <--> cloud")
@click.argument("src")
@click.argument("dest")
@click.option("-f", "--force", is_flag=True, help="Force to copy")
Expand All @@ -282,6 +289,7 @@ def _tag(runtime: str, tags: t.List[str], remove: bool, quiet: bool) -> None:

@runtime_cmd.command(
"activate",
aliases=["actv"],
help="[Only Standalone]Activate python runtime environment for development",
)
@click.option("-u", "--uri", help="Runtime uri which has already been restored")
Expand Down
Loading