]> git.rocketbowman.com Git - nom.git/commitdiff
add convenience commands: open/ignore
authorKyle Bowman <kyle+github@rocketbowman.com>
Mon, 27 Jan 2025 02:19:14 +0000 (21:19 -0500)
committerKyle Bowman <kyle+github@rocketbowman.com>
Mon, 27 Jan 2025 02:19:14 +0000 (21:19 -0500)
src/nom/base.py
src/nom/main.py
tests/test_cli.py

index 8f8ec727ffafcd5570af8e9040628b7f5a1e3099..8fa36acd60e351e4ef1eb4f9329f7f8ae4f2626e 100644 (file)
@@ -98,7 +98,7 @@ class NomList(set):
 
     def to_stdout(self, fields=None, show_header=False, delimiter="\t"):
         if not self:
-            raise NomError("There are no entries to write.")
+            print("No entries match the selection.")
         if show_header:
             valid_fields = next(iter(self)).get_fieldnames()
             if fields: 
index 2e3744822e524ac27f1b7fdb88b450200259bcb7..85569d88b5a66dcc78a0188a741c0359564a6dde 100644 (file)
@@ -38,6 +38,13 @@ def cli():
     entry_update_parser.add_argument('--update', dest="updates", nargs="*", help="Update values as key=value pairs")
     entry_update_parser.add_argument('--dry-run', action="store_true", help="when specified, show changes but don't act")
 
+    # Convenience Commands
+    entry_open_parser = entry_subparsers.add_parser("open", parents=[label_parser,filter_parser], help="lists selected urls for piping and marks viewed")
+    entry_open_parser.set_defaults(func=handle_entry_open)
+    entry_ignore_parser = entry_subparsers.add_parser("ignore", parents=[label_parser,filter_parser], help="marks selection viewed")
+    entry_ignore_parser.add_argument('--dry-run', action="store_true", help="when specified, show changes but don't act")
+    entry_ignore_parser.set_defaults(func=handle_entry_ignore)
+
     # Feed subcommand
     feed_parser = subparsers.add_parser('feed', help='Dispatches commands that operate on a table of feeds.')
     feed_subparsers = feed_parser.add_subparsers(dest='feed_command', help='Dispatches feed commands.')
@@ -79,7 +86,8 @@ def handle_entry_update(args):
                 if e in sublist:
                     if not args.dry_run:
                         e.update(key,val)
-                    print(f"For {e.label}, updating {key} from {e.__dict__[key]} to {val}")
+                    else:
+                        print(f"For {e.label}, updating {key} from {e.__dict__[key]} to {val}")
     else:
         feedlist=FeedList.from_csv(FEED_LIST)
         for flitem in feedlist:
@@ -88,6 +96,19 @@ def handle_entry_update(args):
             print(f"Updating from [{str(flitem)}]")
     elist.to_csv(ENTRY_LIST)
 
+def handle_entry_open(args):
+    args.show_header=False
+    args.delim="|"
+    args.fields=["url"]
+    handle_entry_show(args)
+    args.updates=["viewed=True"]
+    args.dry_run=False
+    handle_entry_update(args)
+
+def handle_entry_ignore(args):
+    args.updates=["viewed=True"]
+    handle_entry_update(args)
+
 def handle_feed_show(args):
     feedlist=FeedList.from_csv(FEED_LIST)
     feedlist.to_stdout(show_header=True)
index 6c0e15d0eb6acd47e226238eab424506c5899750..69b7e37ccaf5796779a8b1d9dcb463ee6e06f7a5 100644 (file)
@@ -46,3 +46,10 @@ def test_nom_entry_update_val():
     argv='entry update 1 --update url=https://path/to/new/url'.split(' ')
     args = cli().parse_args(argv)
     assert True
+
+# Passes on it's own. Fails as a suite...
+def test_nom_entry_open():
+    argtest("entry open 2")
+
+def test_nom_entry_ignore():
+    argtest("entry ignore 1 --dry-run")
\ No newline at end of file