Skip to content

Commit

Permalink
fail if not not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed Jan 6, 2024
1 parent fc99585 commit fd5a395
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 40 deletions.
40 changes: 20 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
41 changes: 21 additions & 20 deletions checklists.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "-"
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -83,28 +84,28 @@ 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()

var gitems items.Items
gitems, err = allPersistedItems.ToItems(sess)
if err != nil {
return items.Checklists{}, err
return items.Tasklists{}, err
}

gitems.Filter(items.ItemFilters{
Expand All @@ -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)
Expand All @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -211,6 +215,7 @@ func (i *GetItemsConfig) Run() (items items.Items, err error) {
}

items.FilterAllTypes(i.Filters)

return items, err
}

Expand Down

0 comments on commit fd5a395

Please sign in to comment.