Skip to content

Commit

Permalink
move the logger package at root of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot committed Nov 16, 2023
1 parent 0792ade commit d69c11a
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cmdduplicate/duplicate.go
Expand Up @@ -8,7 +8,7 @@ import (
"flag"
"immich-go/helpers/gen"
"immich-go/immich"
"immich-go/immich/logger"
"immich-go/logger"
"immich-go/ui"
"path"
"sort"
Expand Down
2 changes: 1 addition & 1 deletion cmdmetadata/metadatacmd.go
Expand Up @@ -5,8 +5,8 @@ import (
"flag"
"immich-go/helpers/docker"
"immich-go/immich"
"immich-go/immich/logger"
"immich-go/immich/metadata"
"immich-go/logger"
"math"
"path"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion cmdstack/cmdstack.go
Expand Up @@ -5,7 +5,7 @@ import (
"flag"
"immich-go/helpers/stacking"
"immich-go/immich"
"immich-go/immich/logger"
"immich-go/logger"
"immich-go/ui"
"path"
"sort"
Expand Down
2 changes: 1 addition & 1 deletion cmdtool/cmdalbum/cmdalbum.go
Expand Up @@ -5,7 +5,7 @@ import (
"flag"
"fmt"
"immich-go/immich"
"immich-go/immich/logger"
"immich-go/logger"
"immich-go/ui"
"regexp"
"sort"
Expand Down
2 changes: 1 addition & 1 deletion cmdtool/cmdtool.go
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"immich-go/cmdtool/cmdalbum"
"immich-go/immich"
"immich-go/immich/logger"
"immich-go/logger"
)

func CommandTool(ctx context.Context, ic *immich.ImmichClient, logger *logger.Logger, args []string) error {
Expand Down
63 changes: 36 additions & 27 deletions cmdupload/e2e_upload_folder_test.go
Expand Up @@ -8,7 +8,7 @@ import (
"errors"
"fmt"
"immich-go/immich"
"immich-go/immich/logger"
"immich-go/logger"
"testing"
"time"

Expand Down Expand Up @@ -39,35 +39,33 @@ func TestE2eUpload(t *testing.T) {
resetImmich bool
expectError bool
}{
/*
{
name: "upload google photos",
args: []string{
"-google-photos",
"../../test-data/low_high/Takeout",
},
resetImmich: true,
expectError: false,
{
name: "upload google photos",
args: []string{
"-google-photos",
"../../test-data/low_high/Takeout",
},
{
name: "upload folder",
args: []string{
"../../test-data/low_high/high",
},
// resetImmich: true,
expectError: false,
resetImmich: true,
expectError: false,
},
{
name: "upload folder",
args: []string{
"../../test-data/low_high/high",
},
{
name: "upload folder",
args: []string{
"../../test-data/low_high/high",
},
// resetImmich: true,
expectError: false,
// resetImmich: true,

expectError: false,
},
{
name: "upload folder",
args: []string{
"../../test-data/low_high/high",
},
*/

// resetImmich: true,
expectError: false,
},
{
name: "upload folder *.jpg",
args: []string{
Expand All @@ -87,6 +85,17 @@ func TestE2eUpload(t *testing.T) {
// resetImmich: true,
expectError: false,
},

{
name: "upload folder *.jpg - dry run",
args: []string{
"-dry-run",
"../../test-data/full_takeout (copy)/Takeout/Google Photos/Photos from 2023",
},

// resetImmich: true,
expectError: false,
},
}

logger := logger.NewLogger(logger.Debug, true, false)
Expand Down
36 changes: 35 additions & 1 deletion cmdupload/upload.go
Expand Up @@ -14,8 +14,8 @@ import (
"immich-go/helpers/gen"
"immich-go/helpers/stacking"
"immich-go/immich"
"immich-go/immich/logger"
"immich-go/immich/metadata"
"immich-go/logger"
"io/fs"
"math"
"path"
Expand Down Expand Up @@ -62,6 +62,7 @@ type UpCmd struct {
DryRun bool // Display actions but don't change anything
ForceSidecar bool // Generate a sidecar file for each file (default: TRUE)
CreateStacks bool // Stack jpg/raw/burst (Default: TRUE)
SelectTypes StringList // List of extensions to be imported

AssetIndex *AssetIndex // List of assets present on the server
deleteServerList []*immich.Asset // List of server assets to remove
Expand Down Expand Up @@ -138,11 +139,32 @@ func NewUpCmd(ctx context.Context, ic iClient, log *logger.Logger, args []string
"Stack jpg/raw or bursts (default TRUE)")

// cmd.BoolVar(&app.Delete, "delete", false, "Delete local assets after upload")

cmd.Var(&app.SelectTypes, "select-types", "list of selected extensions separated by a comma")

err = cmd.Parse(args)
if err != nil {
return nil, err
}

if len(app.SelectTypes) > 0 {
l := []string{}
for _, e := range app.SelectTypes {
if !strings.HasPrefix(e, ".") {
e = "." + e
}
e = strings.ToLower(e)
if _, err = fshelper.MimeFromExt(e); err != nil {
err = errors.Join(err, fmt.Errorf("unsupported extension '%s'", e))
}
l = append(l, e)
}
if err != nil {
return nil, err
}
app.SelectTypes = l
}

app.fsys, err = fshelper.ParsePath(cmd.Args(), app.GooglePhotos)
if err != nil {
return nil, err
Expand Down Expand Up @@ -758,3 +780,15 @@ func keys[M ~map[K]V, K comparable, V any](m M) []K {
}
return r
}

type StringList []string

func (sl *StringList) Set(s string) error {
l := strings.Split(s, ",")
(*sl) = append((*sl), l...)
return nil
}

func (sl StringList) String() string {
return strings.Join(sl, ", ")
}
2 changes: 1 addition & 1 deletion cmdupload/upload_test.go
Expand Up @@ -7,7 +7,7 @@ import (
"immich-go/assets"
"immich-go/helpers/gen"
"immich-go/immich"
"immich-go/immich/logger"
"immich-go/logger"
"reflect"
"slices"
"testing"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,6 +1,6 @@
module immich-go

go 1.20
go 1.21

require (
github.com/google/uuid v1.3.1
Expand Down
12 changes: 8 additions & 4 deletions helpers/fshelper/parseArgs.go
Expand Up @@ -61,11 +61,15 @@ func ParsePath(args []string, googlePhoto bool) ([]fs.FS, error) {
}

for pa, l := range p.paths {
f, err := newPathFS(pa, l)
if err != nil {
p.err = errors.Join(err)
if len(l) > 0 {
f, err := newPathFS(pa, l)
if err != nil {
p.err = errors.Join(err)
} else {
fsys = append(fsys, f)
}
} else {
fsys = append(fsys, f)
fsys = append(fsys, os.DirFS(pa))
}
}

Expand Down
2 changes: 0 additions & 2 deletions immich/immich.go
Expand Up @@ -76,8 +76,6 @@ func (l *List[T]) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &l.list)
}

type StringList struct{ List[string] }

type myBool bool

func (b myBool) String() string {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -12,7 +12,7 @@ import (
"immich-go/cmdupload"
"immich-go/helpers/tzone"
"immich-go/immich"
"immich-go/immich/logger"
"immich-go/logger"
"os"
"os/signal"
)
Expand Down

0 comments on commit d69c11a

Please sign in to comment.