From fd5a39570552816aad250dbb683816674e06113b Mon Sep 17 00:00:00 2001 From: Jon Hadfield Date: Fri, 5 Jan 2024 20:37:34 +0000 Subject: [PATCH] fail if not not found. --- .golangci.yml | 40 ++++++++++++++++++++-------------------- checklists.go | 41 +++++++++++++++++++++-------------------- tag.go | 5 +++++ 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 00e8784..70b17d1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -145,26 +145,26 @@ linters-settings: # Check for plain error comparisons comparison: true - exhaustive: - # check switch statements in generated files also - check-generated: false - # presence of "default" case in switch statements satisfies exhaustiveness, - # even if all enum members are not listed - default-signifies-exhaustive: false - # enum members matching the supplied regex do not have to be listed in - # switch statements to satisfy exhaustiveness - ignore-enum-members: "" - # consider enums only in package scopes, not in inner scopes - package-scope-only: false - - exhaustivestruct: - # Struct Patterns is list of expressions to match struct packages and names - # The struct packages have the form example.com/package.ExampleStruct - # The matching patterns can use matching syntax from https://pkg.go.dev/path#Match - # If this list is empty, all structs are tested. - struct-patterns: - - '*.Test' - - 'example.com/package.ExampleStruct' +# exhaustive: +# # check switch statements in generated files also +# check-generated: false +# # presence of "default" case in switch statements satisfies exhaustiveness, +# # even if all enum members are not listed +# default-signifies-exhaustive: false +# # enum members matching the supplied regex do not have to be listed in +# # switch statements to satisfy exhaustiveness +# ignore-enum-members: "" +# # consider enums only in package scopes, not in inner scopes +# package-scope-only: false +# +# exhaustivestruct: +# # Struct Patterns is list of expressions to match struct packages and names +# # The struct packages have the form example.com/package.ExampleStruct +# # The matching patterns can use matching syntax from https://pkg.go.dev/path#Match +# # If this list is empty, all structs are tested. +# struct-patterns: +# - '*.Test' +# - 'example.com/package.ExampleStruct' forbidigo: # Forbid the following identifiers (identifiers are written using regexp): diff --git a/checklists.go b/checklists.go index ceb8825..6b97aba 100644 --- a/checklists.go +++ b/checklists.go @@ -2,17 +2,18 @@ package sncli import ( "fmt" + "slices" + "time" + "github.com/alexeyco/simpletable" "github.com/gookit/color" "github.com/jonhadfield/gosn-v2/cache" "github.com/jonhadfield/gosn-v2/items" - "slices" - "time" ) -func conflictedWarning([]items.Checklist) string { - if len(items.Checklists{}) > 0 { - return color.Yellow.Sprintf("%d conflicted versions", len(items.Checklists{})) +func conflictedWarning([]items.Tasklist) string { + if len(items.Tasklists{}) > 0 { + return color.Yellow.Sprintf("%d conflicted versions", len(items.Tasklists{})) } return "-" @@ -52,17 +53,17 @@ func (ci *ListChecklistsInput) Run() (err error) { return nil } -// construct a map of duplicates -func getChecklistsDuplicatesMap(checklistNotes items.Notes) (map[string][]items.Checklist, error) { - duplicates := make(map[string][]items.Checklist) +// construct a map of duplicates. +func getChecklistsDuplicatesMap(checklistNotes items.Notes) (map[string][]items.Tasklist, error) { + duplicates := make(map[string][]items.Tasklist) for x := range checklistNotes { if checklistNotes[x].DuplicateOf != "" { // checklist is a duplicate // get the checklist content - cl, err := checklistNotes[x].Content.ToCheckList() + cl, err := checklistNotes[x].Content.ToTaskList() if err != nil { - return map[string][]items.Checklist{}, err + return map[string][]items.Tasklist{}, err } // skip trashed content @@ -73,7 +74,7 @@ func getChecklistsDuplicatesMap(checklistNotes items.Notes) (map[string][]items. cl.UUID = checklistNotes[x].UUID cl.UpdatedAt, err = time.Parse(timeLayout, checklistNotes[x].UpdatedAt) if err != nil { - return map[string][]items.Checklist{}, err + return map[string][]items.Tasklist{}, err } duplicates[checklistNotes[x].DuplicateOf] = append(duplicates[checklistNotes[x].DuplicateOf], cl) @@ -83,20 +84,20 @@ func getChecklistsDuplicatesMap(checklistNotes items.Notes) (map[string][]items. return duplicates, nil } -func getChecklists(sess *cache.Session) (items.Checklists, error) { +func getChecklists(sess *cache.Session) (items.Tasklists, error) { var so cache.SyncOutput so, err := Sync(cache.SyncInput{ Session: sess, }, true) if err != nil { - return items.Checklists{}, err + return items.Tasklists{}, err } var allPersistedItems cache.Items if err = so.DB.All(&allPersistedItems); err != nil { - return items.Checklists{}, err + return items.Tasklists{}, err } allItemUUIDs := allPersistedItems.UUIDs() @@ -104,7 +105,7 @@ func getChecklists(sess *cache.Session) (items.Checklists, error) { var gitems items.Items gitems, err = allPersistedItems.ToItems(sess) if err != nil { - return items.Checklists{}, err + return items.Tasklists{}, err } gitems.Filter(items.ItemFilters{ @@ -118,7 +119,7 @@ func getChecklists(sess *cache.Session) (items.Checklists, error) { }, }) - var checklists items.Checklists + var checklists items.Tasklists checklistNotes := gitems.Notes() duplicatesMap, err := getChecklistsDuplicatesMap(checklistNotes) @@ -136,16 +137,16 @@ func getChecklists(sess *cache.Session) (items.Checklists, error) { continue } - var cl items.Checklist - cl, err = checklistNotes[x].Content.ToCheckList() + var cl items.Tasklist + cl, err = checklistNotes[x].Content.ToTaskList() if err != nil { - return items.Checklists{}, err + return items.Tasklists{}, err } cl.UUID = checklistNotes[x].UUID cl.UpdatedAt, err = time.Parse(timeLayout, checklistNotes[x].UpdatedAt) if err != nil { - return items.Checklists{}, err + return items.Tasklists{}, err } cl.Duplicates = duplicatesMap[checklistNotes[x].UUID] diff --git a/tag.go b/tag.go index 9b5ddba..518be91 100644 --- a/tag.go +++ b/tag.go @@ -108,6 +108,10 @@ func tagNotes(i tagNotesInput) (err error) { } } + if len(typeUUIDs[common.SNItemTypeNote]) == 0 { + return errors.New("note not found") + } + // update existing (and just created) tags to reference matching uuids // determine which TAGS need updating and create list to sync back to server var tagsToPush items.Tags @@ -211,6 +215,7 @@ func (i *GetItemsConfig) Run() (items items.Items, err error) { } items.FilterAllTypes(i.Filters) + return items, err }