diff --git a/dagshub/common/cli.py b/dagshub/common/cli.py index e5bafe67..e6749ca6 100644 --- a/dagshub/common/cli.py +++ b/dagshub/common/cli.py @@ -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") @@ -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 """ config.quiet = quiet or ctx.obj["quiet"] diff --git a/tests/common/test_cli.py b/tests/common/test_cli.py new file mode 100644 index 00000000..fd197260 --- /dev/null +++ b/tests/common/test_cli.py @@ -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