-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcreate.py
More file actions
90 lines (80 loc) · 2.73 KB
/
create.py
File metadata and controls
90 lines (80 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from typing import Optional
import typer
from pyscript import app, cli, plugins
from pyscript._generator import create_project
@app.command()
def create(
app_or_file_name: Optional[str] = typer.Argument(
None, help="The name of your new app or path to an input .py script"
),
app_description: str = typer.Option(None, help="App description"),
author_name: str = typer.Option(None, help="Name of the author"),
author_email: str = typer.Option(None, help="Email of the author"),
pyscript_version: str = typer.Option(
None,
"--pyscript-version",
help="If provided, defines what version of pyscript will be used to create the app",
),
project_type: str = typer.Option(
"app",
"--project-type",
help="Type of project that is being created. Supported types are: 'app'",
),
wrap: bool = typer.Option(
False,
"-w",
"--wrap",
help="Use wrap mode i.e. embed a python script into an HTML file",
),
command: Optional[str] = typer.Option(
None,
"-c",
"--command",
help="If provided, embed a single command string. Meant to be used with `--wrap`",
),
output: Optional[str] = typer.Option(
None,
"-o",
"--output",
help="""Name of the resulting HTML output file. Meant to be used with `-w/--wrap`""",
),
):
"""
Create a new pyscript project with the passed in name, creating a new
directory in the current directory. Alternatively, use `--wrap` so as to embed
a python file instead.
"""
if not app_or_file_name and not command:
app_or_file_name = typer.prompt("App name", default="my-pyscript-app")
if app_or_file_name and command:
raise cli.Abort("Cannot provide both an input '.py' file and '-c' option.")
if (output or command) and (not wrap):
raise cli.Abort(
"""`--output/-o`, and `--command/-c`
are meant to be used with `--wrap/-w`"""
)
if not app_description:
app_description = typer.prompt("App description", default="")
if not author_name:
author_name = typer.prompt("Author name", default="")
if not author_email:
author_email = typer.prompt("Author email", default="")
try:
create_project(
app_or_file_name,
app_description,
author_name,
author_email,
pyscript_version,
project_type,
wrap,
command,
output,
)
except FileExistsError:
raise cli.Abort(
f"A directory called {app_or_file_name} already exists in this location."
)
@plugins.register
def pyscript_subcommand():
return create