Skip to content

Commit

Permalink
feat(cli): unified the display format of description in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
yeyong.yu committed Jul 14, 2021
1 parent eb925f3 commit 5fe279d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tensorbay/cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
write_config,
)

_INDENT = " " * 4
INDENT = " " * 4


def _implement_auth( # pylint: disable=too-many-arguments
Expand Down Expand Up @@ -129,5 +129,5 @@ def _check_args_and_options(arg1: str, arg2: str, get: bool, unset: bool, is_all


def _echo_formatted_profile(name: str, value: str) -> None:
formatted_value = value.replace("\n", f"\n{_INDENT}")
formatted_value = value.replace("\n", f"\n{INDENT}")
click.echo(f"{name} = {formatted_value}\n")
22 changes: 18 additions & 4 deletions tensorbay/cli/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

"""Implementation of gas draft."""

from textwrap import indent
from typing import Dict, Optional, Tuple

import click

from ..client.gas import DatasetClientType
from ..client.struct import ROOT_COMMIT_ID
from ..exception import ResourceNotExistError
from .auth import INDENT
from .tbrn import TBRN, TBRNType
from .utility import edit_message, error, format_hint, get_dataset_client, get_gas

Expand All @@ -21,6 +23,11 @@
# And an empty draft message aborts the creation.
"""

_FULL_DRAFT_MESSAGE = """Branch:{}({})
{}
"""


def _implement_draft( # pylint: disable=too-many-arguments
obj: Dict[str, str], tbrn: str, is_list: bool, edit: bool, close: bool, message: Tuple[str, ...]
Expand Down Expand Up @@ -86,15 +93,22 @@ def _echo_draft(
error(f'The branch "{branch_name}" does not exist')

if branch.commit_id != ROOT_COMMIT_ID:
click.echo(f"Branch: {branch_name}({branch.commit_id})")
commit_id = branch.commit_id
else:
click.echo(f"Branch: {branch_name}")
commit_id = ""

if not title:
title = "<no title>"
click.echo(f"\n {title}\n")
if description:
click.echo(f" {description}\n")
description = f"\n{indent(description, INDENT)}"
draft_message = "\n".join((title, description))
click.echo(
_FULL_DRAFT_MESSAGE.format(
branch_name,
commit_id,
draft_message,
)
)


def _edit_draft(dataset_client: DatasetClientType, info: TBRN, message: Tuple[str, ...]) -> None:
Expand Down
12 changes: 7 additions & 5 deletions tensorbay/cli/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"""Implementation of gas log."""

from datetime import datetime
from textwrap import indent
from typing import Dict, Optional

import click

from ..client.struct import Commit
from .auth import INDENT
from .tbrn import TBRN
from .utility import get_dataset_client, get_gas, shorten

Expand All @@ -19,9 +21,6 @@
Date: {}
{}
{}
"""


Expand All @@ -45,10 +44,13 @@ def _get_oneline_log(commit: Commit) -> str:


def _get_full_log(commit: Commit) -> str:
description = commit.description
if description:
description = f"\n{indent(description, INDENT)}\n"
commit_message = "\n".join((commit.title, description))
return _FULL_LOG.format(
commit.commit_id,
commit.committer.name,
datetime.fromtimestamp(commit.committer.date).strftime("%a %b %d %H:%M:%S %y"),
commit.title,
commit.description,
commit_message,
)

0 comments on commit 5fe279d

Please sign in to comment.