cli: fix installation of subpackages
This commit is contained in:
@@ -1,6 +1,51 @@
|
|||||||
# !/usr/bin/env python3
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from . import admin, secrets, ssh
|
||||||
|
from .errors import ClanError
|
||||||
|
|
||||||
|
has_argcomplete = True
|
||||||
|
try:
|
||||||
|
import argcomplete
|
||||||
|
except ImportError:
|
||||||
|
has_argcomplete = False
|
||||||
|
|
||||||
|
|
||||||
|
# this will be the entrypoint under /bin/clan (see pyproject.toml config)
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description="cLAN tool")
|
||||||
|
subparsers = parser.add_subparsers()
|
||||||
|
|
||||||
|
parser_admin = subparsers.add_parser("admin")
|
||||||
|
admin.register_parser(parser_admin)
|
||||||
|
|
||||||
|
# Currently broken
|
||||||
|
# parser_config = subparsers.add_parser("config")
|
||||||
|
# try:
|
||||||
|
# config.register_parser(parser_config)
|
||||||
|
# except subprocess.CalledProcessError as e:
|
||||||
|
# warn(f"The config command does not work in the nix sandbox: {e}")
|
||||||
|
|
||||||
|
parser_ssh = subparsers.add_parser("ssh", help="ssh to a remote machine")
|
||||||
|
ssh.register_parser(parser_ssh)
|
||||||
|
|
||||||
|
parser_secrets = subparsers.add_parser("secrets", help="manage secrets")
|
||||||
|
secrets.register_parser(parser_secrets)
|
||||||
|
|
||||||
|
if has_argcomplete:
|
||||||
|
argcomplete.autocomplete(parser)
|
||||||
|
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
parser.print_help()
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
if hasattr(args, "func"):
|
||||||
|
try:
|
||||||
|
args.func(args)
|
||||||
|
except ClanError as e:
|
||||||
|
print(f"{sys.argv[0]}: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
from .cli import main
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from . import admin, config, secrets, ssh
|
|
||||||
from .errors import ClanError
|
|
||||||
from .tty import warn
|
|
||||||
|
|
||||||
has_argcomplete = True
|
|
||||||
try:
|
|
||||||
import argcomplete
|
|
||||||
except ImportError:
|
|
||||||
has_argcomplete = False
|
|
||||||
|
|
||||||
|
|
||||||
# this will be the entrypoint under /bin/clan (see pyproject.toml config)
|
|
||||||
def main() -> None:
|
|
||||||
parser = argparse.ArgumentParser(description="cLAN tool")
|
|
||||||
subparsers = parser.add_subparsers()
|
|
||||||
|
|
||||||
parser_admin = subparsers.add_parser("admin")
|
|
||||||
admin.register_parser(parser_admin)
|
|
||||||
|
|
||||||
parser_config = subparsers.add_parser("config")
|
|
||||||
try:
|
|
||||||
config.register_parser(parser_config)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
warn(f"The config command does not work in the nix sandbox: {e}")
|
|
||||||
|
|
||||||
parser_ssh = subparsers.add_parser("ssh", help="ssh to a remote machine")
|
|
||||||
ssh.register_parser(parser_ssh)
|
|
||||||
|
|
||||||
parser_secrets = subparsers.add_parser("secrets", help="manage secrets")
|
|
||||||
secrets.register_parser(parser_secrets)
|
|
||||||
|
|
||||||
if has_argcomplete:
|
|
||||||
argcomplete.autocomplete(parser)
|
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
|
||||||
parser.print_help()
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
if hasattr(args, "func"):
|
|
||||||
try:
|
|
||||||
args.func(args)
|
|
||||||
except ClanError as e:
|
|
||||||
print(f"{sys.argv[0]}: {e}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -6,10 +6,10 @@ build-backend = "setuptools.build_meta"
|
|||||||
name = "clan"
|
name = "clan"
|
||||||
description = "cLAN CLI tool"
|
description = "cLAN CLI tool"
|
||||||
dynamic = [ "version" ]
|
dynamic = [ "version" ]
|
||||||
scripts = { clan = "clan_cli:main" }
|
scripts = { clan = "clan_cli.cli:main" }
|
||||||
|
|
||||||
[tool.setuptools]
|
[tool.setuptools.packages]
|
||||||
packages = [ "clan_cli" ]
|
find = {}
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail"
|
addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail"
|
||||||
|
|||||||
Reference in New Issue
Block a user