From: Shane Jaroch Date: Wed, 14 Feb 2024 20:34:49 +0000 (-0500) Subject: list bugs too (not just submitting) X-Git-Tag: v0.2.8.dev0~42 X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=e5e4af2f6e9b726f08e5b4f7e41b35cabf2f39d8;p=nutratech%2Fcli.git list bugs too (not just submitting) --- diff --git a/ntclient/__main__.py b/ntclient/__main__.py index 0d48b65..aa58e24 100644 --- a/ntclient/__main__.py +++ b/ntclient/__main__.py @@ -114,6 +114,8 @@ def main(args: list = None) -> int: # type: ignore print("Unforeseen error, run with --debug for more info: " + repr(exception)) print("You can open an issue here: %s" % __url__) print("Or send me an email with the debug output: %s" % __email__) + print("Or, run the bug report command.") + print() handle_runtime_exception(args, exception) finally: if CLI_CONFIG.debug: diff --git a/ntclient/argparser/__init__.py b/ntclient/argparser/__init__.py index b7299c0..b4800d7 100644 --- a/ntclient/argparser/__init__.py +++ b/ntclient/argparser/__init__.py @@ -323,7 +323,19 @@ def build_calc_subcommand(subparsers: argparse._SubParsersAction) -> None: def build_subcommand_bug(subparsers: argparse._SubParsersAction) -> None: - """Report bugs""" + """List and report bugs""" bug_parser = subparsers.add_parser("bug", help="report bugs") - bug_parser.set_defaults(func=parser_funcs.bugs_report) + bug_subparser = bug_parser.add_subparsers(title="bug subcommands") + bug_parser.add_argument( + "--all", action="store_true", help="include already submitted bugs, too" + ) + bug_parser.set_defaults(func=parser_funcs.bugs_list) + + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Report (bug) + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + bug_report_parser = bug_subparser.add_parser( + "report", help="submit/report all bugs" + ) + bug_report_parser.set_defaults(func=parser_funcs.bugs_report) diff --git a/ntclient/argparser/funcs.py b/ntclient/argparser/funcs.py index ada945e..9b0b77e 100644 --- a/ntclient/argparser/funcs.py +++ b/ntclient/argparser/funcs.py @@ -338,7 +338,25 @@ def calc_lbm_limits(args: argparse.Namespace) -> tuple: return 0, result -def bugs_report() -> tuple: - """Report a bug""" - n_submissions = ntclient.services.bugs.submit() +def bugs_list(args: argparse.Namespace) -> tuple: + """List bug reports that have een saved""" + _bugs_list = ntclient.services.bugs.list_bugs() + + print(f"You have {len(_bugs_list)} unique bugs to report/submit! Good job.") + print() + + for bug in _bugs_list: + # Skip submitted bugs by default + if bug[-1] != 0 and not args.all: + continue + # Print all (except noisy stacktrace) + print(", ".join(str(x) for x in bug if "\n" not in str(x))) + + return 0, _bugs_list + + +# pylint: disable=unused-argument +def bugs_report(args: argparse.Namespace) -> tuple: + """Report bugs""" + n_submissions = ntclient.services.bugs.submit_bugs() return 0, n_submissions diff --git a/ntclient/services/api/__init__.py b/ntclient/services/api/__init__.py index e5d6990..7135c9d 100644 --- a/ntclient/services/api/__init__.py +++ b/ntclient/services/api/__init__.py @@ -49,5 +49,4 @@ class ApiClient: # TODO: move this outside class; support with host iteration helper method def post_bug(self, bug: tuple) -> None: """Post a bug report to the developer.""" - print("posting bug report...") self.post("bug", dict(bug)) diff --git a/ntclient/services/bugs.py b/ntclient/services/bugs.py index 7f2bd39..75e047d 100644 --- a/ntclient/services/bugs.py +++ b/ntclient/services/bugs.py @@ -44,17 +44,25 @@ INSERT INTO bug raise -def submit() -> int: +def list_bugs() -> list: + """List all bugs.""" + sql_bugs = sql_nt("SELECT * FROM bug WHERE submitted = 0") + return sql_bugs + + +def submit_bugs() -> int: """Submit bug reports to developer, return n_submitted.""" sql_bugs = sql_nt("SELECT * FROM bug WHERE submitted = 0") api_client = ntclient.services.api.ApiClient() n_submitted = 0 print(f"submitting {len(sql_bugs)} bug reports...") + print("_" * len(sql_bugs)) for bug in sql_bugs: - # print(", ".join(str(x) for x in bug)) + print(".", end="", flush=True) api_client.post_bug(bug) n_submitted += 1 + print() # 1 / 0 # force exception # raise Exception("submitting bug reports failed")