Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions dagshub/common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def repo():
pass


@repo.command()
@repo.command(short_help="Create a repo, optionally uploading data to it and cloning it locally")
@click.argument("repo_name")
@click.option("-u", "--upload-data", help="Upload data from specified url to new repository")
@click.option("-c", "--clone", is_flag=True, help="Clone repository locally")
Expand All @@ -336,17 +336,21 @@ def repo():
@click.pass_context
def create(ctx, repo_name, upload_data, clone, verbose, quiet):
"""
create a repo and optionally:
Create a repo and optionally:

- upload files to 'data' from a URL dir using `-u` flag. .zip and .tar files are extracted,
other formats copied as is.
\b
- upload a file to 'data' from a URL using the `-u` flag.
.zip and .tar files are extracted, other formats are copied as is.
- clone the repo locally using the `--clone` flag.

- clone the repo locally using `--clone` flag
\b
Example 1:
dagshub repo create mytutorial -u "http://example.com/data.csv" --clone

example 1: dagshub repo create mytutorial -u "http://example.com/data.csv" --clone

example 2: dagshub --host "https://www.dagshub.com"
repo create mytutorial2 -u "http://0.0.0.0:8080/index.html" --clone --verbose
\b
Example 2:
dagshub --host "https://www.dagshub.com" repo create mytutorial2
-u "http://0.0.0.0:8080/index.html" --clone --verbose
Comment thread
coderabbitai[bot] marked this conversation as resolved.
"""

config.quiet = quiet or ctx.obj["quiet"]
Expand Down
47 changes: 47 additions & 0 deletions tests/common/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from click.testing import CliRunner

from dagshub.common.cli import cli


def _help(*args):
result = CliRunner().invoke(cli, [*args, "--help"])
assert result.exit_code == 0, result.output
return result.output


def test_repo_group_help_lists_a_complete_summary_for_create():
"""
The command listing used to be built from the first line of the docstring,
which ended in a colon and read as truncated output.
"""
output = _help("repo")

assert "Create a repo, optionally uploading data to it and cloning it" in output
# The dangling summary the listing used to end on.
assert "create a repo and optionally:" not in output


def test_repo_create_help_keeps_its_structure():
"""
The bullet list and the examples are pre-formatted, so click must not
rewrap them into a single run-on paragraph.
"""
output = _help("repo", "create")

# Assert the rendered structure, not just that fragments appear somewhere:
# a later rewrap could satisfy substring checks while breaking the layout.
lines = [line.rstrip() for line in output.splitlines()]

assert " - upload a file to 'data' from a URL using the `-u` flag." in lines
assert " .zip and .tar files are extracted, other formats are copied as is." in lines
assert " - clone the repo locally using the `--clone` flag." in lines

assert " Example 1:" in lines
assert (
' dagshub repo create mytutorial -u "http://example.com/data.csv" --clone'
in lines
)
assert " Example 2:" in lines

# The rewrapped remnant of the un-escaped bullet.
assert "are extracted, other formats" not in output