]> Nutra Git (v1) - nutratech/cli.git/commitdiff
list bugs too (not just submitting)
authorShane Jaroch <chown_tee@proton.me>
Wed, 14 Feb 2024 20:34:49 +0000 (15:34 -0500)
committerShane Jaroch <chown_tee@proton.me>
Wed, 14 Feb 2024 20:34:49 +0000 (15:34 -0500)
ntclient/__main__.py
ntclient/argparser/__init__.py
ntclient/argparser/funcs.py
ntclient/services/api/__init__.py
ntclient/services/bugs.py

index 0d48b651be4dea3d56a11a9af5637736775a32d7..aa58e24d3329f8573ee32f35315e738672f7da81 100644 (file)
@@ -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:
index b7299c087f5a138b3847c4cedf717da1f0bc6ad6..b4800d71a353f81e83aafc3a4c46e3b19ec72d90 100644 (file)
@@ -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)
index ada945e497b1e40217a272b446100120868ead36..9b0b77e044504597c1136960a1ef76aaf9a69d5e 100644 (file)
@@ -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
index e5d6990ae3d9fd43d57a8a7540da841e95c9be29..7135c9d1c2c950017438d591cb67ac7f6ac9a771 100644 (file)
@@ -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))
index 7f2bd39c0947eabc36cf2c1da8b6cc98be544693..75e047d8a81a1b1e118d6c575eb27351a82f79be 100644 (file)
@@ -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")