]> git.rocketbowman.com Git - nom.git/commitdiff
feat: add ability to update column
authorKyle Bowman <kyle+github@rocketbowman.com>
Sat, 25 Jan 2025 23:26:54 +0000 (18:26 -0500)
committerKyle Bowman <kyle+github@rocketbowman.com>
Sat, 25 Jan 2025 23:26:54 +0000 (18:26 -0500)
src/nom/base.py
src/nom/main.py
tests/test_cli.py

index 3ed198e4895f49fa45a872647474a9fbf0c208d4..dc5192c2fd9100c74df1ac21a92a9399f107420b 100644 (file)
@@ -22,6 +22,9 @@ class NomListItem(BaseModel):
     def get_fieldnames(cls):
         return cls.__fields__.keys()
     
+    def update(self, key, val):
+        self.__setattr__(key, val)
+    
     # TODO: What if there's a pipe in one of the fields? 
     def to_str(self, delimiter: str ='|'):
         return delimiter.join([str(v) for v in self.__dict__.values()])
index fc76b2d40ad22c15e3fb611bbf5d138f386f2450..3aafdbe41b263b5392eb93f74803556891032e19 100644 (file)
@@ -26,8 +26,10 @@ def cli():
     entry_subparsers = entry_parser.add_subparsers(dest='entry_command', help='Dispatches entry commands.')
     entry_show_parser = entry_subparsers.add_parser('show', parents=[label_parser], help='Show entries.')
     entry_show_parser.set_defaults(func=handle_entry_show) 
-    entry_update_parser = entry_subparsers.add_parser('update', help='Update entry data.')
+    entry_update_parser = entry_subparsers.add_parser('update', parents=[label_parser], help='update entry data.')
     entry_update_parser.set_defaults(func=handle_entry_update)
+    entry_update_parser.add_argument('--update', dest="updates", nargs="*", help="Update values as key=value pairs")
+
 
     # Feed subcommand
     feed_parser = subparsers.add_parser('feed', help='Dispatches commands that operate on a table of feeds.')
@@ -49,11 +51,23 @@ def handle_entry_show(args):
     elist.to_stdout(show_header=True)
 
 def handle_entry_update(args):
-    elist=EntryList()
-    feedlist=FeedList.from_csv(FEED_LIST)
-    for flitem in feedlist:
-        elist += flitem.to_feed().to_entrylist()
-        print(f"Updating from [{str(flitem)}]")
+    if not ENTRY_LIST.exists():
+        elist=EntryList()
+    else:
+        elist = EntryList.from_csv(ENTRY_LIST)
+    if args.updates:
+        sublist = elist.select(lambda e: e.label in args.label)
+        for u in args.updates:
+            key, val = u.split('=')
+            for e in elist:
+                if e in sublist:
+                    e.update(key,val)
+    else:
+        feedlist=FeedList.from_csv(FEED_LIST)
+        for flitem in feedlist:
+            elist += flitem.to_feed().to_entrylist()
+            print(f"Updating from [{str(flitem)}]")
     elist.to_csv(ENTRY_LIST)
 
 def handle_feed_show(args):
index 35649c2164a3ebc50559006baab8232b1f4b6435..6ee4f1aafcb4694f42c1ef8b8076e1c1650fc075 100644 (file)
@@ -1,5 +1,5 @@
 from nom.main import cli, dispatch
-
+from nom.base import NomListItem
 
 def argtest(argstr):
     """ Asserts that the CLI entry points don't raise errors. """
@@ -24,3 +24,9 @@ def test_nom_entry_show_one():
 
 def test_nom_entry_update():
     argtest('entry update')
+
+def test_nom_entry_update_val():
+    NomListItem.update = print("Don't really update") #This actually works, lol
+    argv='entry update 1 --update url=https://path/to/new/url'.split(' ')
+    args = cli().parse_args(argv)
+    assert True