]> git.rocketbowman.com Git - nom.git/commitdiff
add numbering that persists w/ line items
authorKyle Bowman <kylebowman14@gmail.com>
Tue, 21 Jan 2025 04:10:09 +0000 (23:10 -0500)
committerKyle Bowman <kylebowman14@gmail.com>
Tue, 21 Jan 2025 04:10:09 +0000 (23:10 -0500)
src/nom/base.py
src/nom/cli.py
src/nom/main.py
tests/data/entry_multi.csv
tests/test_cli.py
tests/test_entry.py

index fbd4caa0336394d3cf2109a07ae92f43e542b459..77a89ef37e49b81bf21066d56353cf402e0bd12c 100644 (file)
@@ -11,6 +11,7 @@ Predicate = Callable[..., bool]
 
 
 class NomListItem(BaseModel):
+    label: Optional[int] = -1
 
     @abstractmethod
     def __hash__(self):
@@ -41,6 +42,11 @@ class NomList(set):
         else:
             super().__init__(elements)
 
+        # Number items and persist via label attribute
+        for i, item in enumerate(self, start=1):
+            if not item.label:
+                item.__setattr__('label',i)
+
     def __add__(self, other):
         return self.__class__(self.union(other))
     
index c39736d43751d43a068f2fdba5ee1ca976a6ece7..a3e7d1a6c9e673c0ce59fd2882ea807f957469ce 100644 (file)
@@ -14,5 +14,6 @@ def cli():
     feed_parser = subparsers.add_parser('feed', help='Feed related commands')
     feed_subparsers = feed_parser.add_subparsers(dest='feed_command', help='Feed sub-command help')
     feed_update_parser = feed_subparsers.add_parser('update', help='Update feed')
+    feed_update_parser = feed_subparsers.add_parser('show', help='Show feeds')
 
     return parser
index 26850f752fceb8b8ca52c4205b8e7acdfe555023..de5fbe0553265c2fbb3cca026ec793b3aec1bba7 100644 (file)
@@ -24,6 +24,8 @@ def main(args=['nom'].append(sys.argv)):
         elist.to_stdout()
     elif args.command == "feed" and args.feed_command == "update":
         feedlist.fetch_feeds(FEED_CACHE)
+    elif args.command == "feed" and args.feed_command == "show":
+        feedlist.to_stdout()
     else:
         raise NomError("That option is not yet supported.")
 
index bb54feec9030007720415d7608d4c5446eb45ddd..e369cf2b211f0451afc52972af658bdfc6ce0845 100644 (file)
@@ -1,3 +1,3 @@
-title|url|date|feed_url|feed_alias|viewed|summary\r
-Entry One|https://path/to/entry2.html|date|https://path/to/feed.atom|feed1|False|\r
-Entry Two|https://path/to/entry3.html|date|https://path/to/feed.atom|feed2|True|\r
+label|title|url|date|feed_url|feed_alias|viewed|summary\r
+1|Entry One|https://path/to/entry2.html|date|https://path/to/feed.atom|feed1|False|\r
+2|Entry Two|https://path/to/entry3.html|date|https://path/to/feed.atom|feed2|True|\r
index 7c1c08658fb7a0aa69d36084ca892c11f6d6e3ae..7e7036bbd6f4bb665eb49e7581450980b85f3a2b 100644 (file)
@@ -7,4 +7,8 @@ def test_nom_entry_show():
 
 def test_nom_feed_update():
     main(args='feed update'.split(' '))
+    assert True
+
+def test_nom_feed_show():
+    main(args='feed show'.split(' '))
     assert True
\ No newline at end of file
index df215b36b3bf10221c9d9cade8bc3d967d3ed19b..30b307f4d81c694b18bfd6bbf8bb9a85e65cc0d0 100644 (file)
@@ -44,3 +44,8 @@ def test_elist_addition(elist_multi, elist_single):
 def test_elist_select(elist_multi):
     viewed = elist_multi.select(lambda e: e.viewed)
     assert len(viewed) < len(elist_multi)
+
+def test_elist_select_entry(elist_multi):
+    second = elist_multi.select(lambda e: e.label == 2).pop()
+    assert second.label == 2
+    assert second.title == "Entry Two"