Skip to content

Commit

Permalink
feat(cli): add "gas tag" command to list tags
Browse files Browse the repository at this point in the history
PR Closed: #600
  • Loading branch information
QianBao8902 committed May 26, 2021
1 parent 6e8251d commit 13ed0cd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tensorbay/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,21 @@ def branch(obj: Dict[str, str], tbrn: str, verbose: bool) -> None:
_implement_branch(obj, tbrn, verbose)


@cli.command()
@click.argument("tbrn", type=str)
@click.pass_obj
def tag(obj: Dict[str, str], tbrn: str) -> None:
"""Work with tag.\f
Arguments:
obj: A dict contains config information.
tbrn: The tbrn of the dataset.
""" # noqa: D301,D415
from .tag import _implement_tag

_implement_tag(obj, tbrn)


if __name__ == "__main__":
cli() # pylint: disable=no-value-for-parameter
32 changes: 32 additions & 0 deletions tensorbay/cli/tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
#
# Copyright 2021 Graviti. Licensed under MIT License.
#

"""Implementation of gas tag."""
import sys
from typing import Dict

import click

from ..client.gas import DatasetClientType
from .tbrn import TBRN, TBRNType
from .utility import get_dataset_client, get_gas


def _implement_tag(obj: Dict[str, str], tbrn: str) -> None:
info = TBRN(tbrn=tbrn)

if info.type != TBRNType.DATASET:
click.echo(f'To operate a tag, "{info}" must be a dataset', err=True)
sys.exit(1)

gas = get_gas(**obj)
dataset_client = get_dataset_client(gas, info)

_list_tags(dataset_client)


def _list_tags(dataset_client: DatasetClientType) -> None:
for tag in dataset_client.list_tags():
click.echo(tag.name)

0 comments on commit 13ed0cd

Please sign in to comment.