]> git.rocketbowman.com Git - nom.git/commitdiff
add tests and show --full vs urls (default)
authorKyle Bowman <kyle+github@rocketbowman.com>
Sun, 26 Jan 2025 23:44:29 +0000 (18:44 -0500)
committerKyle Bowman <kyle+github@rocketbowman.com>
Sun, 26 Jan 2025 23:44:29 +0000 (18:44 -0500)
src/nom/base.py
src/nom/main.py
tests/test_cli.py

index dc5192c2fd9100c74df1ac21a92a9399f107420b..4d0a78c72f7b62dd17e7109a4a1bf4d604c95fdc 100644 (file)
@@ -26,8 +26,11 @@ class NomListItem(BaseModel):
         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()])
+    def to_str(self, fields: Optional[list[str]]=None, delimiter: str ='|'):
+        if not fields:
+            fields = [str(k) for k in self.__dict__.keys()]
+        lst = [str(v) for k,v in self.__dict__.items() if k in fields]
+        return delimiter.join(lst)
 
     def to_dict(self):
         return vars(self)
@@ -66,9 +69,9 @@ class NomList(set):
         items = {item for item in self if predicate(item)}
         return self.__class__(items)
     
-    def to_stdout(self):
-        for item in self.items:
-            print(item.to_str(delimiter="\t"))
+    #def to_stdout(self, fields=[]):
+    #    for item in self.items:
+    #        print(item.to_str(fields=fields, delimiter="\t"))
 
     @classmethod
     def from_csv(cls, file: Path, delimiter="|"):
@@ -97,12 +100,12 @@ class NomList(set):
             for item in self:
                 writer.writerow(item.to_dict())
     
-    def to_stdout(self, show_header=False, delimiter="|"):
+    def to_stdout(self, fields=None, show_header=False, delimiter="|"):
         if not self:
             raise NomError("There are no entries to write.")
         if show_header:
             headers = next(iter(self)).get_fieldnames()
             print(delimiter.join(headers))
         for item in self:
-            print(item.to_str())
+            print(item.to_str(fields=fields, delimiter=delimiter))
     
\ No newline at end of file
index 3aafdbe41b263b5392eb93f74803556891032e19..3336fd19320254140412c70b52cbe5017d3f5a83 100644 (file)
@@ -26,6 +26,7 @@ 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_show_parser.add_argument('--full', action='store_true', help="when specified, show the full entry data, not just the URLs.")
     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")
@@ -48,7 +49,10 @@ def handle_entry_show(args):
     elist = EntryList.from_csv(ENTRY_LIST)
     if args.label:
         elist = elist.select(lambda e: e.label in args.label)
-    elist.to_stdout(show_header=True)
+    if args.full:
+        elist.to_stdout(show_header=True)
+    else:
+        elist.to_stdout(fields=['url'])
 
 def handle_entry_update(args):
     if not ENTRY_LIST.exists():
index 6ee4f1aafcb4694f42c1ef8b8076e1c1650fc075..556fb1a3bc21bde5ee08685c9d3159273d4556a4 100644 (file)
@@ -19,11 +19,24 @@ def test_nom_feed_show():
 def test_nom_entry_show():
     argtest('entry show')
 
+def test_nom_entry_show_full():
+    argtest('entry show --full')
+
 def test_nom_entry_show_one():
     argtest('entry show 1')
 
-def test_nom_entry_update():
+def test_nom_entry_update_no_elist(tmp_path):
+    ENTRY_LIST = tmp_path / "entry_list" / "default"
+    argtest('entry update')
+
+def test_nom_entry_update_from_feeds():
+    argtest('entry update')
+
+def test_nom_entry_update_value(tmp_path):
+    ENTRY_LIST = tmp_path / "entry_list" / "default"
+    # Note: it looks like select selects None by default.
     argtest('entry update')
+    argtest('entry update 1 --update url="https://path/to/other.html')
 
 def test_nom_entry_update_val():
     NomListItem.update = print("Don't really update") #This actually works, lol