Skip to content

Commit

Permalink
Merge pull request #117 from Undertone0809/v1.3.4/optimize-cli
Browse files Browse the repository at this point in the history
refactor: optimize cli usage
  • Loading branch information
Undertone0809 authored Sep 3, 2024
2 parents 1d35e47 + 40492d1 commit 00cc351
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 19 additions & 11 deletions p3g/client.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import argparse
import subprocess
import sys
from importlib.metadata import version


def main():
if len(sys.argv) < 2:
print("Usage: p3g <command>")
print("Available commands: generate")
sys.exit(1)

command = sys.argv[1]

if command == "generate":
generate_proj()
parser = argparse.ArgumentParser(description="P3G CLI tool")
subparsers = parser.add_subparsers(dest="command")
generate_parser = subparsers.add_parser("generate", help="Generate a new project")
generate_parser.set_defaults(func=generate_proj)
parser.add_argument(
"--version", action="version", version=f'%(prog)s {version("p3g")}'
)
args = parser.parse_args()

if hasattr(args, "func"):
args.func()
else:
print(f"Unknown command: {command}")
print(f"Unknown command: {args.command}")
parser.print_help()
sys.exit(1)


def generate_proj():
subprocess.run(["cookiecutter", "gh:Undertone0809/P3G", "--checkout", "v1.3.1"])
subprocess.run(
["cookiecutter", "gh:Undertone0809/P3G", "--checkout", version("p3g")]
)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "p3g"
version = "1.3.3"
version = "1.3.4"
description = "Python Packages Project Generator"
readme = "README.md"
authors = ["Zeeland <zeeland4work@gmail.com>"]
Expand Down

0 comments on commit 00cc351

Please sign in to comment.