Skip to content

Commit

Permalink
feat(cli): implement basic structure of "gas draft" command
Browse files Browse the repository at this point in the history
PR Closed: #546
  • Loading branch information
rexzheng324-c committed May 17, 2021
1 parent ef116b6 commit aa218af
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 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 @@ -148,5 +150,30 @@ def dataset(obj: Dict[str, str], name: str, is_delete: bool, yes: bool) -> None:
_implement_dataset(obj, name, is_delete, yes)


@cli.command()
@click.argument("tbrn", type=str)
@click.option("-l", "--list", "is_list", is_flag=True, help="List the drafts.")
@click.option("-t", "--title", type=str, default="", help="The title of the draft.")
@click.pass_obj
def draft(
obj: Dict[str, str],
tbrn: str,
is_list: bool,
title: str,
) -> None:
"""Work with draft.
Arguments:
obj: A dict contains config information.
tbrn: The tbrn of the dataset.
is_list: Whether to list the drafts.
title: The title of the draft.
""" # noqa: D301,D415
from .draft import _implement_draft

_implement_draft(obj, tbrn, is_list, title)


if __name__ == "__main__":
cli() # pylint: disable=no-value-for-parameter
32 changes: 32 additions & 0 deletions tensorbay/cli/draft.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 draft."""

import sys
from typing import Dict

import click

from .tbrn import TBRN, TBRNType


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

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

0 comments on commit aa218af

Please sign in to comment.