added tag add command
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user