-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
155 lines (122 loc) · 3.97 KB
/
cli.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"""Definition of the CLI commands for Ginpar.
This module defines the different commands available for the ginpar static
content generator.
Examples
--------
To get the list of available commands and options run::
ginpar
"""
import click
@click.group()
@click.version_option(message="%(prog)s v%(version)s")
def cli():
"""
Ginpar is a static content generator for interactive P5.js sketches,
awkwardly named after Generative Interactive Parametrisable Canvases.
"""
pass
@cli.command()
@click.option(
"--path",
"-p",
default="public",
type=click.Path(),
help=(
"The PATH where the site will be built. [ <config.build_path>, public ] "
"This path is relative to the current directory. When no option is provided "
"Ginpar will read the <config.build_path> from the configuration file."
),
)
def build(path):
"""Build the project content into PATH.
`ginpar build` will read your configuration file, fetch all the sketches inside
your <config.content_path>, and build your static site inside PATH, which
defaults to <config.build_path>, or public if it doesn't exist.
This operation will wipe all the content from PATH in each run, so you must not
make modifications you expect to preserve.
"""
from ginpar.build import build as ginpar_build
click.echo("")
ginpar_build(path)
click.echo("")
@cli.command()
@click.option(
"--force",
"-f",
default=False,
is_flag=True,
help=(
"If Ginpar finds an existing directory with the same name of the "
"project being initialized, it'll force its removal. "
"Only do this if you're completely sure you want to do it."
),
)
@click.option(
"--quick",
"-q",
default=False,
is_flag=True,
help=(
"Skip the prompts and use the default values for the configuration file. "
"You can still modify the variables later by manually updating your "
"configuration file."
),
)
def init(force, quick):
"""Initialize a new project in PATH.
`ginpar init` will prompt you for a series of values that will be used to
generate the configuration and file structure of your project.
"""
from ginpar.init import init as ginpar_init
click.echo("")
ginpar_init(force, quick)
click.echo("")
@cli.command()
@click.argument("sketch")
def new(sketch):
"""Create a new SKETCH.
`ginpar new` will create a new sketch structure inside your <config.content_path>.
You must specify the name of the sketch.
If there's an existing sketch with the same name, it'll throw an error and ask
for a different name.
"""
from ginpar.new import new as ginpar_new
click.echo("")
ginpar_new(sketch)
click.echo("")
@cli.command()
@click.option(
"--force",
"-f",
default=False,
is_flag=True,
help=(
"If Ginpar finds an existing directory with the same name of the sample content, "
"it'll force its removal. "
"Only do this if you're completely sure you want to do it."
),
)
def quickstart(force):
"""Import a working sample project.
`ginpar quickstart` will download the contents of the sample project, hosted
at github: davidomarf/ginpar-quickstart in the current directory.
"""
from ginpar.quickstart import quickstart as ginpar_quickstart
click.echo("")
ginpar_quickstart(force)
click.echo("")
@cli.command()
@click.option("--port", "-p", default=8080, help="Port of the server")
def serve(port):
"""Start a new server in localhost:PORT.
`ginpar serve` will trigger `ginpar build`, and start a new server inside
<config.build_path>.
Every time you modify a file that is part of the project's source code the
site gets built again.
"""
from ginpar.serve import serve as ginpar_serve
click.echo("")
ginpar_serve(port)
click.echo("")
if __name__ == "__main__":
cli()