From eaf9b692813c821555d90f6b2914ce5d5ef5689d Mon Sep 17 00:00:00 2001 From: Kyle Bowman Date: Sat, 25 Jan 2025 14:54:18 -0500 Subject: [PATCH] feat: display header with nom * show --- src/nom/base.py | 7 +++++-- src/nom/main.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/nom/base.py b/src/nom/base.py index 5cd0591..3ed198e 100644 --- a/src/nom/base.py +++ b/src/nom/base.py @@ -65,7 +65,7 @@ class NomList(set): def to_stdout(self): for item in self.items: - print(item.to_str(delimeter="\t")) + print(item.to_str(delimiter="\t")) @classmethod def from_csv(cls, file: Path, delimiter="|"): @@ -94,9 +94,12 @@ class NomList(set): for item in self: writer.writerow(item.to_dict()) - def to_stdout(self): + def to_stdout(self, 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()) \ No newline at end of file diff --git a/src/nom/main.py b/src/nom/main.py index 2b55385..c1d5535 100644 --- a/src/nom/main.py +++ b/src/nom/main.py @@ -44,12 +44,12 @@ 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) - elist.to_stdout() + elist.to_stdout(show_header=True) elif args.command == "feed" and args.feed_command == "update": feedlist.update_labels() feedlist.fetch_feeds(FEED_CACHE) elif args.command == "feed" and args.feed_command == "show": - feedlist.to_stdout() + feedlist.to_stdout(show_header=True) else: raise NomError("That option is not yet supported.") -- 2.39.5