copier-shiv/src/cli.py.jinja

85 lines
2 KiB
Django/Jinja

import code
import io
import sys
import art
import click
from rich import console as rich_console, pretty, traceback
import src
from src.utils import _install, _uninstall, update_from_gitea
class RichCommand(click.Group):
def format_usage(self, ctx, formatter):
sio = io.StringIO()
console = rich_console.Console(file=sio, force_terminal=True)
console.print("Usage: ./[[ module_name ]] [COMMAND]")
console.print(" All dependencies are contained within. Use your")
console.print(" chosen Python version to launch this file.")
formatter.write(sio.getvalue())
@click.command(
cls=RichCommand,
context_settings=dict(help_option_names=["-h", "--help", "--halp"]),
)
@click.pass_context
@click.version_option(version=src.__version__, prog_name="[[ module_name ]]")
@click.option(
"--update",
is_flag=True,
help="Check Gitea for a new version and auto-update.",
)
@click.option(
"--shell",
"shell",
is_flag=True,
default=False,
help="Launch a REPL for testing.",
)
@click.option(
"--install",
"install",
is_flag=True,
default=False,
help="Install as a service on Ubuntu systems."
)
@click.option(
"--uninstall",
"uninstall",
is_flag=True,
default=False,
help="Uninstall as an Ubuntu service."
)
def entrypoint(update, shell, install, uninstall):
"""
Launch [[ project_name ]] or drop into a command line REPL.
"""
if update:
update_from_gitea()
sys.exit()
if shell:
banner = art.text2art("[[ module_name ]]")
pretty.install() # type: ignore
traceback.install() # traceback handler
code.interact(local=globals(), banner=banner)
sys.exit()
if install:
_install()
sys.exit()
if uninstall:
_uninstall()
sys.exit()
main()
def main() -> None:
"""Put main program functionality here."""
print("Nothing here...")
if __name__ == "__main__":
entrypoint()