Skip to content

Commit

Permalink
Reduce the number of available options for different CLI commands
Browse files Browse the repository at this point in the history
Some of them were unnecessary and only added complexity to the code
base, such as specifying `--path=PATH` in the `ginpar build` command.

Although some of them were potentially useful, there are more elegant
solutions, such as specifying them in the configuration file.
  • Loading branch information
davidomarf committed Oct 23, 2019
1 parent 76ecc30 commit 231f72f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 39 deletions.
101 changes: 66 additions & 35 deletions ginpar/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
@click.version_option(message="%(prog)s v%(version)s")
def cli():
"""
Ginpar is an extra simple static content generator for interactive and parametrisable p5 canvases.
Ginpar is a static content generator for interactive P5.js sketches,
awkwardly named after Generative Interactive Parametrisable Canvases.
"""
pass

Expand All @@ -23,10 +24,22 @@ def cli():
"-p",
default="public",
type=click.Path(),
help="The PATH for the generated site.\nDefault = public",
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 a static website in 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("")
Expand All @@ -40,46 +53,52 @@ def build(path):
"-f",
default=False,
is_flag=True,
help="Remove existing directories that may interfere with the initialization",
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 configuration prompts and use the default values",
)
@click.option(
"--path",
"-p",
default="",
help="The PATH to initialize the project. Defaults to ./",
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, path, quick):
"""Initialize a new project in PATH"""
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, path, quick)
ginpar_init(force, quick)
click.echo("")


@cli.command()
@click.argument("sketch", default="new-sketch")
@click.option(
"--path",
"-p",
default="sketches",
type=click.Path(),
help="The path for the newly created sketch",
)
def new(sketch, path):
"""Create a new SKETCH in PATH"""
click.secho(f"Attemping to create `{sketch}` in `{path}/`", fg="blue")
@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, path)
ginpar_new(sketch)
click.echo("")


Expand All @@ -89,24 +108,36 @@ def new(sketch, path):
"-f",
default=False,
is_flag=True,
help="Remove existing directories that may interfere the quickstart",
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."
),
)
@click.option(
"--path", "-p", default="./", help="The path the demo content will be copied to."
)
def quickstart(force, path):
"""Load a working example in PATH"""
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, path)
ginpar_quickstart(force)
click.echo("")


@cli.command()
@click.option("--port", "-p", default="8080", help="Port for the web server")
@click.option("--port", "-p", default=8080, help="Port of the server")
def serve(port):
"""Serve the content using 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("")
Expand Down
2 changes: 1 addition & 1 deletion ginpar/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def prompt_site_config():
}


def init(force, path, quick):
def init(force, quick):
""""""
_config_template = _jinja_env.get_template("config.json.jinja2")

Expand Down
2 changes: 1 addition & 1 deletion ginpar/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
import click


def new(sketch, path):
def new(sketch):
click.secho("You're in new", fg="blue")
6 changes: 4 additions & 2 deletions ginpar/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ def init_config():
error("Failure. It already exists.")


def quickstart(force, path):
def quickstart(force):
path = "ginpar-quickstart"

if force:
alert("Forcing quickstart. This will replace existent directories and files.")
try_remove("sketches")
try_remove("themes")
try_remove("config.json")
echo("")

info(f"Copying demo content into `{os.path.abspath(path)}`")
copy_folder(_THEMES_DIR, "themes")
copy_folder(_SKETCHES_DIR, "sketches")
Expand Down

0 comments on commit 231f72f

Please sign in to comment.