nut/nut/__main__.py

51 lines
1.4 KiB
Python

from .cli import CLI
from .commands.setup import is_nut_workspace, find_template_conflicts, copy_template_files
def help_text():
return [
"%bold%%cyan%nut CLI: tiny shell, big squirrel energy :3%reset%",
]
def main() -> int:
cli = CLI(help_callback=help_text)
cli.command(
"init",
help="Create an empty nut workspace or reinitialize with --force",
description=(
"Initialize a nut development workspace by creating a Nutfile and default project files. "
"If a Nutfile already exists, initialization should fail unless --force is used."
),
).flag(
"force",
"f",
help="Reinitialize even when a Nutfile already exists",
).arg(
"path",
nargs="?",
default=".",
help="Directory to initialize (default: current directory)",
).handle(cmd_init)
return cli.run()
def cmd_init(args, flags) -> int:
dest_dir = args[0]
force = flags["force"]
conflicts = find_template_conflicts(dest_dir)
if conflicts and not force:
print("Some files already exist that would be overwritten:")
for file in conflicts:
print(f" {file}")
print("Use --force to overwrite existing files.")
return 1
copy_template_files(dest_dir, force=force, checked=True)
return 0
if __name__ == "__main__":
raise SystemExit(main())