Atlas - cli.py

Home / npkg-testing / tools / npkg Lines: 9 | Size: 3182 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1import argparse 2 3from .commands import ( 4 cmd_build, 5 cmd_clean, 6 cmd_install, 7 cmd_installed, 8 cmd_list, 9 cmd_package, 10 cmd_uninstall, 11) 12from .console import fail 13 14 15def build_parser() -> argparse.ArgumentParser: 16 parser = argparse.ArgumentParser( 17 prog="npkg", 18 description="Simple package helper for the Nexus monorepo", 19 formatter_class=argparse.RawDescriptionHelpFormatter, 20 epilog=( 21 "Examples:\n" 22 " npkg list\n" 23 " npkg build hello-world\n" 24 " npkg build '*'\n" 25 " npkg package hello-world\n" 26 " npkg install hello-world\n" 27 " npkg clean '*'\n" 28 " npkg installed\n" 29 " npkg uninstall hello-world" 30 ), 31 ) 32 33 sub = parser.add_subparsers(dest="command", required=True) 34 35 list_parser = sub.add_parser("list", help="List available packages") 36 list_parser.set_defaults(func=cmd_list) 37 38 build_parser = sub.add_parser("build", help="Build package(s) (supports wildcards)") 39 build_parser.add_argument( 40 "packages", 41 nargs="+", 42 help="Package selectors (name/path or wildcards like '*', 'hello-*', 'bin/*')", 43 ) 44 build_parser.set_defaults(func=cmd_build) 45 46 package_parser = sub.add_parser("package", help="Create package archive(s) (.tar.gz, supports wildcards)") 47 package_parser.add_argument( 48 "packages", 49 nargs="+", 50 help="Package selectors (name/path or wildcards like '*', 'hello-*', 'bin/*')", 51 ) 52 package_parser.set_defaults(func=cmd_package) 53 54 install_parser = sub.add_parser("install", help="Install a package") 55 install_parser.add_argument("package", help="Package name or package directory path") 56 install_parser.add_argument( 57 "--root", 58 default="/opt/npkg", 59 help="Installation root directory (default: /opt/npkg)", 60 ) 61 install_parser.set_defaults(func=cmd_install) 62 63 clean_parser = sub.add_parser("clean", help="Run package clean command (supports wildcards)") 64 clean_parser.add_argument( 65 "packages", 66 nargs="+", 67 help="Package selectors (name/path or wildcards like '*', 'hello-*', 'bin/*')", 68 ) 69 clean_parser.set_defaults(func=cmd_clean) 70 71 installed_parser = sub.add_parser("installed", help="List installed packages from manifest database") 72 installed_parser.add_argument( 73 "--root", 74 default="/opt/npkg", 75 help="Installation root directory (default: /opt/npkg)", 76 ) 77 installed_parser.set_defaults(func=cmd_installed) 78 79 uninstall_parser = sub.add_parser("uninstall", help="Uninstall a package") 80 uninstall_parser.add_argument("package", help="Package name") 81 uninstall_parser.add_argument( 82 "--root", 83 default="/opt/npkg", 84 help="Installation root directory (default: /opt/npkg)", 85 ) 86 uninstall_parser.set_defaults(func=cmd_uninstall) 87 88 return parser 89 90 91def main(argv: list[str] | None = None) -> int: 92 parser = build_parser() 93 args = parser.parse_args(argv) 94 try: 95 return int(args.func(args)) 96 except ValueError as error: 97 fail(str(error)) 98 return 2 99
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.