Skip to content

Commit

Permalink
Check description in Phalanx CLI
Browse files Browse the repository at this point in the history
Check that the description starts with a capital letter and is not
excessively long inside the Phalanx CLI so that it won't create new
applications that immediately fail the application docs test.
  • Loading branch information
rra committed Sep 28, 2023
1 parent 931ea71 commit f376463
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/phalanx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import json
import re
import sys
from pathlib import Path

Expand Down Expand Up @@ -121,7 +122,10 @@ def application() -> None:
"-d",
"--description",
prompt="Short description",
help="Short description of the new application.",
help=(
"Short description of the new application. Must start with capital"
" letter and, with the application name, be less than 80 characters."
),
)
@click.option(
"-s",
Expand All @@ -142,6 +146,10 @@ def application_create(
"""
if not config:
config = _find_config()
if len(name) + 3 + len(description) > 80:
raise click.UsageError("Name plus description is too long")
if not re.match("[A-Z0-9]", description):
raise click.UsageError("Description must start with capital letter")
factory = Factory(config)
application_service = factory.create_application_service()
application_service.create_application(
Expand Down
29 changes: 29 additions & 0 deletions tests/cli/application_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,35 @@ def test_create(tmp_path: Path) -> None:
assert environment.applications["hips"].chart["sources"][0] == expected


def test_create_errors(tmp_path: Path) -> None:
config_path = tmp_path / "phalanx"
shutil.copytree(str(phalanx_test_path()), str(config_path))
result = run_cli(
"application",
"create",
"some-really-long-app-name-please-do-not-do-this",
"--description",
"Some really long description on top of the app name",
"--config",
str(config_path),
needs_config=False,
)
assert "Name plus description is too long" in result.output
assert result.exit_code == 2
result = run_cli(
"application",
"create",
"app",
"--description",
"lowercase description",
"--config",
str(config_path),
needs_config=False,
)
assert "Description must start with capital letter" in result.output
assert result.exit_code == 2


def test_create_prompt(tmp_path: Path) -> None:
config_path = tmp_path / "phalanx"
shutil.copytree(str(phalanx_test_path()), str(config_path))
Expand Down

0 comments on commit f376463

Please sign in to comment.