post tag command

This commit is contained in:
Nathan McCarty 2025-02-08 23:58:10 -05:00
parent e05269b9a3
commit 7a5ef790f3
2 changed files with 29 additions and 1 deletions

28
blog
View file

@ -254,3 +254,31 @@ multi MAIN(
}
}
}
#| Add or remove a tag to a post
multi MAIN(
"post",
"tag",
#| The id of the post to display information for
Int $id,
#| The tag to add/remove
Str $tag,
#| remove the tag instead of adding it
Bool :$remove,
#| The path of the database directory
IO::Path(Str) :$db-dir = $default-db-dir,
) {
my $db = read-db $db-dir;
my $post = $db.posts{$id.Int};
if $remove {
die "Post did not have requested tag"
unless $tag ~~ any($post.tags);
my $index = $post.tags.first: $tag;
$post.tags.=grep(* ne $tag);
} else {
die "Post already had requested tag"
if $tag ~~ any($post.tags);
$post.tags.push: $tag;
}
$db.write: $db-dir;
}