Skip to content

Commit

Permalink
Merge pull request #1556 from Avaiga/refactor/#1472-update-create-cli…
Browse files Browse the repository at this point in the history
…-command

Refactor/#1472 - Update create cli command
  • Loading branch information
trgiangdo authored Jul 22, 2024
2 parents 7fdbb19 + bcea560 commit 15de9a2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 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 used to create the 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()
4 changes: 2 additions & 2 deletions taipy/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ and limitations under the License.
Taipy is a Python library for creating Business Applications. More information on our
[website](https://www.taipy.io).

Taipy templates is a repository that contains templates and scaffoldings created and
Taipy templates is a repository that contains application templates created and
maintained by Taipy. It helps users getting started with a simple and ready-to-go application.

A more in depth documentation of taipy can be found [here](https://docs.taipy.io).
Expand All @@ -38,7 +38,7 @@ taipy create
```
or
```bash
taipy create --template "default"
taipy create --application "default"
```

After providing necessary information, your new application is created in the current
Expand Down
4 changes: 2 additions & 2 deletions taipy/templates/package_desc.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Taipy is a Python library for creating Business Applications. More information o
[website](https://www.taipy.io). Taipy is split into multiple packages including *taipy-templates*
to let users install the minimum they need.

Taipy templates is a repository that contains templates created and
Taipy templates is a repository that contains application templates created and
maintained by Taipy. It helps users getting started with a simple and ready-to-go application.

To create a Taipy application using this template, first you need to install Taipy (> 2.2).
Expand All @@ -29,7 +29,7 @@ taipy create
```
or
```bash
taipy create --template "default"
taipy create --application "default"
```

After providing necessary information, your new application is created in the current
Expand Down
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 15de9a2

Please sign in to comment.