From ddb519432097b06353295d36987c959ebd08279a Mon Sep 17 00:00:00 2001 From: clerie Date: Wed, 6 Jul 2022 12:50:16 +0200 Subject: [PATCH] Add project script for cli --- mitel_ommclient2/cli.py | 16 +++++++++------- pyproject.toml | 3 +++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mitel_ommclient2/cli.py b/mitel_ommclient2/cli.py index 5d1059d..416ecb3 100755 --- a/mitel_ommclient2/cli.py +++ b/mitel_ommclient2/cli.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 -from mitel_ommclient2 import OMMClient2 -from mitel_ommclient2.exceptions import ENoEnt -from mitel_ommclient2.messages import GetAccount, Ping -import time - import argparse import getpass +import time import traceback +from . import OMMClient2 +from .exceptions import ENoEnt +from .messages import GetAccount, Ping + # exit handling with argparse is a bit broken even with exit_on_error=False, so we hack this def error_instead_exit(self, message): raise argparse.ArgumentError(None, message) @@ -22,8 +22,7 @@ def format_list(v): return fl -if __name__ == "__main__": - +def main(): connect_parser = argparse.ArgumentParser(prog='ommclient2') connect_parser.add_argument("-n", dest="hostname", default="127.0.0.1") connect_parser.add_argument("-u", dest="username", default="omm") @@ -178,3 +177,6 @@ if __name__ == "__main__": print("".join(traceback.format_exception(type(e), e, e.__traceback__))) continue print(format(r)) + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index 3cb496a..c73ec36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,5 +23,8 @@ crypt = [ "rsa", ] +[project.scripts] +ommclient2 = "mitel_ommclient2.cli:main" + [project.urls] "Source" = "https://git.clerie.de/clerie/mitel_ommclient2"