Adds list-tags option

This will list the tags along with the number of number of times it is
used.

An optional --noheader flag can be passed after the command to prevent
the header being printed.

e.g.

```
$ kb list-tags
name              count
----------------  -----
Linux             2
Authentication    1
Pentesting        1
Enumeration       3
Network Protocol  2
```

```
$ kb list-tags --noheader
Linux             2
Authentication    1
Pentesting        1
Enumeration       3
Network Protocol  2
```

This --noheader flag was also added to the list command

Close #10
This commit is contained in:
Jonathan Hodgson 2020-12-20 18:22:39 +00:00
parent ac031344d3
commit b84cf93f4a
2 changed files with 24 additions and 1 deletions

View file

@ -64,3 +64,20 @@ assignTags(){
}
listTags(){
vecho "listTags $*"
cd "$dataDir" || return
local header="--header"
[ "$1" = "--noheader" ] && header=""
echo "SELECT tags.name,COUNT(links.id) count
FROM tags LEFT JOIN links ON tags.id = links.tagID
GROUP BY tags.id" |
sqlite3 --column $header "${sqliteFile}"
#echo "SELECT items.id,items.filename,items.title,items.type,
#GROUP_CONCAT(tags.name,',') tags
#FROM items LEFT JOIN links ON items.id = links.itemID
#LEFT JOIN tags ON links.tagID = tags.id
#GROUP BY items.id;" |
# sqlite3 --column --header "${sqliteFile}"
}