aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2021-07-23 16:26:52 -0400
committerGravatar - 2021-07-26 22:55:13 -0400
commitaf658c7e3a8777e9f71a2e9901983f17cd5cd50f (patch)
tree6cca8fed34d0d79b37e6ef3ed3a1f4c11a000539
parentadd ability to add cards to database (diff)
make sure tagging does not add a tag more than once
-rw-r--r--example/modify_note.md4
-rw-r--r--example/new_note.md4
-rw-r--r--example/underwriter.dbbin28672 -> 36864 bytes
-rwxr-xr-xunderwriter10
4 files changed, 12 insertions, 6 deletions
diff --git a/example/modify_note.md b/example/modify_note.md
new file mode 100644
index 0000000..a0702dd
--- /dev/null
+++ b/example/modify_note.md
@@ -0,0 +1,4 @@
+Modifying a note is the same as [adding a note](new_note).
+
+ underwriter tag modify_note.md usage example
+ underwriter tag modify_note.md command
diff --git a/example/new_note.md b/example/new_note.md
index 7b16a72..ed48f56 100644
--- a/example/new_note.md
+++ b/example/new_note.md
@@ -1,3 +1,3 @@
-Add new notes and tag them using the `add` command.
+Add new notes and tag them using the `tag` command.
- undertaker add new_note.md usage example command
+ undertaker tag new_note.md usage example command
diff --git a/example/underwriter.db b/example/underwriter.db
index 4e2118b..d6df5bd 100644
--- a/example/underwriter.db
+++ b/example/underwriter.db
Binary files differ
diff --git a/underwriter b/underwriter
index fa2bb4f..bff7216 100755
--- a/underwriter
+++ b/underwriter
@@ -64,19 +64,21 @@ WITHOUT ROWID;
return (None, None) if vals is None else vals
def card_add_tags(self, name, tags):
- tagstr,created = self.get_card(name)
+ oldtags,created = self.get_card(name)
if created is None:
created = current_time()
+ oldtags = set([] if oldtags is None else oldtags.split("\t"))
cur = self.make_cursor()
+
+ # XXX: skip tags common to oldtags?
for t in tags:
cur.new_tag(t)
- tagstr = append_tab(tagstr, t)
cur.add_card_to_tag(name, t)
cur.execute(
"INSERT OR REPLACE INTO cards VALUES (?, ?, ?)",
- (name, tagstr, created))
+ (name, "\t".join(list((oldtags | tags))), created))
self.db.commit()
def card_remove_tags(self, name, tags):
@@ -140,7 +142,7 @@ if __name__ == "__main__":
usage()
sys.exit(0)
if args[0] == "tag":
- ctx.card_add_tags(args[1], args[2:])
+ ctx.card_add_tags(args[1], set(args[2:]))
elif args[0] == "remove":
for i in args[1:]:
ctx.remove(i)