use pointers for optional update fields to distinguish empty from unset

This commit is contained in:
2026-03-27 02:41:27 +01:00
parent 81fb9af5e2
commit 74cc7c104a
3 changed files with 19 additions and 11 deletions

View File

@@ -45,7 +45,8 @@ var editCmd = &cobra.Command{
}
if content, err := os.ReadFile(tmp.Name()); err == nil {
if err := d.UpdateNode(args[0], db.UpdateParams{Content: string(content)}); err != nil {
c := string(content)
if err := d.UpdateNode(args[0], db.UpdateParams{Content: &c}); err != nil {
fmt.Fprintln(os.Stderr, "failed to update:", err)
return
}

View File

@@ -61,8 +61,17 @@ var updateCmd = &cobra.Command{
uRmTags = append(uRmTags, "_prio::low", "_prio::medium", "_prio::high")
}
uParams := db.UpdateParams{Title: uTitle, Content: uContent, DueDate: uDue, ClearDue: uClearDue,
uParams := db.UpdateParams{ClearDue: uClearDue,
AddTags: uAddTags, RemoveTags: uRmTags, AddRels: addRels, RemoveRels: rmRels}
if cmd.Flags().Changed("title") {
uParams.Title = &uTitle
}
if cmd.Flags().Changed("content") {
uParams.Content = &uContent
}
if cmd.Flags().Changed("due") {
uParams.DueDate = &uDue
}
if err := d.UpdateNode(args[0], uParams); err != nil {
fmt.Fprintln(os.Stderr, "failed to update:", err)
return