added tag add command

This commit is contained in:
2024-02-15 15:31:49 +01:00
parent 5a2e182453
commit 6d1a81a279
4 changed files with 44 additions and 13 deletions

View File

@@ -12,13 +12,13 @@ type Tags struct {
Tags map[string]string `json:"tags"`
}
var tags Tags
func readTags(filename string) (*Tags, error) {
bytes, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
var tags Tags
err = json.Unmarshal(bytes, &tags)
if err != nil {
return nil, err
@@ -42,7 +42,15 @@ func writeTags(filename string, tags *Tags) error {
}
func addTag(tags *Tags, tagKey string, tagValue string) {
tags, err := readTags("data.json")
if err != nil {
log.Fatalf("Failed to read tags: %v", err)
}
tags.Tags[tagKey] = tagValue
err = writeTags("data.json", tags)
if err != nil {
log.Fatalf("Failed to write tags: %v", err)
}
}
func removeTag(tags *Tags, tagKey string) {
@@ -56,15 +64,5 @@ func modifyTag(tags *Tags, tagKey string, newTagValue string) {
}
func debugTags() {
tags, err := readTags("data.json")
if err != nil {
log.Fatalf("Failed to read tags: %v", err)
}
addTag(tags, "new_command", "a new command description")
err = writeTags("data.json", tags)
if err != nil {
log.Fatalf("Failed to write tags: %v", err)
}
addTag(&tags, "new_command", "a new command description")
}