Skip to content

Commit

Permalink
feat(cli): support creating draft in "gas draft" command
Browse files Browse the repository at this point in the history
  • Loading branch information
rexzheng324-c committed May 17, 2021
1 parent 079878f commit 3fdcf98
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
11 changes: 6 additions & 5 deletions tensorbay/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
Use 'gas ls' to list data.
Use 'gas draft' to operate a draft.
"""

from typing import Dict
Expand Down Expand Up @@ -151,18 +153,17 @@ def dataset(obj: Dict[str, str], name: str, is_delete: bool, yes: bool) -> None:
@cli.command()
@click.argument("tbrn", type=str)
@click.option("-t", "--title", type=str, default="", help="The title of the draft.")
@click.option("-l", "--list", "is_list", is_flag=True, help="List the draft.")
@click.option("-l", "--list", "is_list", is_flag=True, help="List the drafts.")
@click.pass_obj
def draft( # pylint: disable=invalid-name
obj: Dict[str, str], tbrn: str, title: str, is_list: bool
) -> None:
"""Work with draft\f
def draft(obj: Dict[str, str], tbrn: str, title: str, is_list: bool) -> None:
"""Work with draft
Arguments:
obj: A dict contains config information.
tbrn: Path to be listed, like "tb:KITTI:seg1". If empty, list names of all datasets.
title: The title of the draft.
is_list: Whether to list the draft.
""" # noqa: D301,D415
from .draft import _implement_draft

Expand Down
25 changes: 22 additions & 3 deletions tensorbay/cli/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,46 @@
# Copyright 2021 Graviti. Licensed under MIT License.
#

"""Implementation of gas create."""
"""Implementation of gas draft."""

import sys
from typing import Dict

import click

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


def _implement_draft(
obj: Dict[str, str], tbrn: str, title: str, is_list: bool # pylint: disable=unused-argument
) -> None:
gas = get_gas(**obj)
info = TBRN(tbrn=tbrn)
dataset_client = get_dataset_client(gas, info)

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

if title:
# todo: create draft base on revision
_create_draft(dataset_client, info, title)
elif is_list:
pass

if is_list:
pass
else:
_create_draft(dataset_client, info, title)


def _create_draft(dataset_client: DatasetClientType, info: TBRN, title: str) -> None:
dataset_client.create_draft(title=title)
draft_tbrn = TBRN(info.dataset_name, draft_number=dataset_client.status.draft_number).get_tbrn()
click.echo(f"{draft_tbrn} is created successfully")
try:
click.echo(f"Branch: main({dataset_client.get_commit('main').commit_id}) -> main")
except ResourceNotExistError:
click.echo("Branch: main -> main")
click.echo(f"Title: {title}")

0 comments on commit 3fdcf98

Please sign in to comment.