]> git.rocketbowman.com Git - nom.git/commitdiff
feat: select entries by label
authorKyle Bowman <kyle+github@rocketbowman.com>
Sat, 25 Jan 2025 21:26:12 +0000 (16:26 -0500)
committerKyle Bowman <kyle+github@rocketbowman.com>
Sat, 25 Jan 2025 21:26:12 +0000 (16:26 -0500)
src/nom/main.py
tests/test_cli.py

index c1d55350693bdb900d3e389e52c9628a56f38607..a56a89ddcaff8ac1e3f6d9e535b1469f158748ff 100644 (file)
@@ -12,13 +12,19 @@ FEED_LIST=Path.home()  / ".local" / "share" / "nom" / "feedlist" / "default"
 ENTRY_LIST=Path.home() / ".local" / "share" / "nom" / "entrylist" / "default"
 
 def cli():
+
+    # Label Parser
+    label_parser = ArgumentParser(add_help=False)
+    label_parser.add_argument('label', nargs='*', type=int)
+    
+    # Main Parser 
     parser = ArgumentParser(description="Nom Script")
     subparsers = parser.add_subparsers(dest='command', help='Sub-command help')
 
     # Entry subcommand
     entry_parser = subparsers.add_parser('entry', help='Dispatches commands that operate on a table of entries.')
     entry_subparsers = entry_parser.add_subparsers(dest='entry_command', help='Dispatches entry commands.')
-    entry_show_parser = entry_subparsers.add_parser('show', help='Show entries.')
+    entry_show_parser = entry_subparsers.add_parser('show', parents=[label_parser], help='Show entries.')
     entry_update_parser = entry_subparsers.add_parser('update', help='Update entry data.')
 
     # Feed subcommand
@@ -26,7 +32,6 @@ def cli():
     feed_subparsers = feed_parser.add_subparsers(dest='feed_command', help='Dispatches feed commands.')
     feed_update_parser = feed_subparsers.add_parser('update', help='Update feed')
     feed_show_parser = feed_subparsers.add_parser('show', help='Show feeds')
-    
     return parser
 
 
@@ -44,6 +49,8 @@ def main(args=['nom'].append(sys.argv)):
         elist.to_csv(ENTRY_LIST)
     elif args.command == "entry" and args.entry_command == "show":
         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)
     elif args.command == "feed" and args.feed_command == "update":
         feedlist.update_labels()
index 87137788106ef438aed8186c0f0ab66b0dec8b56..b7fb51de22a0481e14ae909c1463d91d608c663a 100644 (file)
@@ -5,6 +5,10 @@ def test_nom_entry_show():
     main(args='entry show'.split(' '))
     assert True
 
+def test_nom_entry_show_one():
+    main(args='entry show 1'.split(' '))
+    assert True
+
 def test_nom_feed_update():
     main(args='feed update'.split(' '))
     assert True