Skip to content

Commit

Permalink
refactor: rename _ScaffoldCLI to _CreateCLI and --template option to …
Browse files Browse the repository at this point in the history
…--application
  • Loading branch information
trgiangdo committed Jul 20, 2024
1 parent 0ae161a commit 074dcab
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions taipy/_cli/_scaffold_cli.py → taipy/_cli/_create_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
from ._base_cli._taipy_parser import _TaipyParser


class _ScaffoldCLI(_AbstractCLI):
class _CreateCLI(_AbstractCLI):
_template_map: Dict[str, str] = {}

_COMMAND_NAME = "create"
_ARGUMENTS = ["--template"]
_ARGUMENTS = ["--application"]

@classmethod
def generate_template_map(cls, template_path: Optional[pathlib.Path] = None):
Expand All @@ -49,10 +49,10 @@ def create_parser(cls):
help="Create a new Taipy application using pre-defined templates.",
)
create_parser.add_argument(
"--template",
"--application",
choices=list(cls._template_map.keys()),
default="default",
help="The Taipy template to create new application.",
help="The template name to create a new Taipy application.",
)

@classmethod
Expand All @@ -61,7 +61,7 @@ def handle_command(cls):
if not args:
return
try:
cookiecutter(cls._template_map[args.template])
cookiecutter(cls._template_map[args.application])
except OutputDirExistsException as err:
error_msg = f"{str(err)}. Please remove the existing directory or provide a new folder name."
print(error_msg) # noqa: T201
Expand Down
8 changes: 4 additions & 4 deletions taipy/_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from taipy.core._version._cli._version_cli import _VersionCLI
from taipy.gui._gui_cli import _GuiCLI

from ._cli._create_cli import _CreateCLI
from ._cli._help_cli import _HelpCLI
from ._cli._run_cli import _RunCLI
from ._cli._scaffold_cli import _ScaffoldCLI
from .version import _get_version


Expand All @@ -46,8 +46,8 @@ def _entrypoint():
_CoreCLI.create_run_parser()

_VersionCLI.create_parser()
_ScaffoldCLI.generate_template_map()
_ScaffoldCLI.create_parser()
_CreateCLI.generate_template_map()
_CreateCLI.create_parser()
_MigrateCLI.create_parser()
_HelpCLI.create_parser()

Expand All @@ -65,7 +65,7 @@ def _entrypoint():
_HelpCLI.handle_command()
_VersionCLI.handle_command()
_MigrateCLI.handle_command()
_ScaffoldCLI.handle_command()
_CreateCLI.handle_command()

_TaipyParser._remove_argument("help")
_TaipyParser._parser.print_help()
2 changes: 1 addition & 1 deletion tests/cli/test_help_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_help_non_existed_command(caplog):


def test_taipy_create_help(capsys):
expected_help = "create [-h] [--template"
expected_help = "create [-h] [--application"

with patch("sys.argv", ["prog", "help", "create"]):
with pytest.raises(SystemExit):
Expand Down
6 changes: 3 additions & 3 deletions tests/templates/test_template_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@


def test_create_cli_with_wrong_arguments(caplog):
with patch("sys.argv", ["prog", "create", "--teamplaet", "default"]):
with patch("sys.argv", ["prog", "create", "--applciation", "default"]):
with pytest.raises(SystemExit):
_entrypoint()
assert "Unknown arguments: --teamplaet. Did you mean: --template?" in caplog.text
assert "Unknown arguments: --applciation. Did you mean: --application?" in caplog.text


def test_create_cli_with_unsupported_template(capsys):
with patch("sys.argv", ["prog", "create", "--template", "not-a-template"]):
with patch("sys.argv", ["prog", "create", "--application", "not-a-template"]):
with pytest.raises(SystemExit):
_entrypoint()
_, err = capsys.readouterr()
Expand Down

0 comments on commit 074dcab

Please sign in to comment.