From: Kyle Bowman Date: Sat, 25 Jan 2025 21:26:12 +0000 (-0500) Subject: feat: select entries by label X-Git-Url: https://git.rocketbowman.com/?a=commitdiff_plain;h=6fa36b7af40e637ce8e4f310f34bc457523cc101;p=nom.git feat: select entries by label --- diff --git a/src/nom/main.py b/src/nom/main.py index c1d5535..a56a89d 100644 --- a/src/nom/main.py +++ b/src/nom/main.py @@ -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() diff --git a/tests/test_cli.py b/tests/test_cli.py index 8713778..b7fb51d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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