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 aa218af commit 31d323b
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tensorbay/cli/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,34 @@

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, is_list: bool, title: str # pylint: disable=unused-argument
) -> None:
def _implement_draft(obj: Dict[str, str], tbrn: str, is_list: bool, title: str) -> 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 is_list:
pass

elif title:
pass

else:
pass
# todo: create draft base on revision
_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 31d323b

Please sign in to comment.