From 602f3446545400a0e39651dc974166cd5ee825e2 Mon Sep 17 00:00:00 2001 From: Seednode Date: Thu, 28 Sep 2023 03:39:16 -0500 Subject: [PATCH] Split sorting types, methods, and functions into their own file --- cmd/files.go | 46 ------------------------------------------ cmd/root.go | 2 +- cmd/sort.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 cmd/sort.go diff --git a/cmd/files.go b/cmd/files.go index f302b42..9750606 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -40,34 +40,6 @@ type scanStatsChannels struct { directoriesSkipped chan int } -type splitPath struct { - base string - number string - extension string -} - -func (splitPath *splitPath) increment() { - length := len(splitPath.number) - - asInt, err := strconv.Atoi(splitPath.number) - if err != nil { - return - } - - splitPath.number = fmt.Sprintf("%0*d", length, asInt+1) -} - -func (splitPath *splitPath) decrement() { - length := len(splitPath.number) - - asInt, err := strconv.Atoi(splitPath.number) - if err != nil { - return - } - - splitPath.number = fmt.Sprintf("%0*d", length, asInt-1) -} - func humanReadableSize(bytes int) string { const unit = 1000 @@ -99,24 +71,6 @@ func kill(path string, cache *fileCache) error { return nil } -func split(path string, regexes *regexes) (*splitPath, int, error) { - p := splitPath{} - - split := regexes.filename.FindAllStringSubmatch(path, -1) - - if len(split) < 1 || len(split[0]) < 3 { - return &splitPath{}, 0, nil - } - - p.base = split[0][1] - - p.number = split[0][2] - - p.extension = split[0][3] - - return &p, len(p.number), nil -} - func newFile(list []string, sortOrder string, regexes *regexes, formats *types.Types) (string, error) { path, err := pickFile(list) if err != nil { diff --git a/cmd/root.go b/cmd/root.go index ef7f261..35b08cc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,7 +12,7 @@ import ( ) const ( - ReleaseVersion string = "0.97.0" + ReleaseVersion string = "0.97.1" ) var ( diff --git a/cmd/sort.go b/cmd/sort.go new file mode 100644 index 0000000..7376404 --- /dev/null +++ b/cmd/sort.go @@ -0,0 +1,57 @@ +/* +Copyright © 2023 Seednode +*/ + +package cmd + +import ( + "fmt" + + "strconv" +) + +type splitPath struct { + base string + number string + extension string +} + +func (splitPath *splitPath) increment() { + length := len(splitPath.number) + + asInt, err := strconv.Atoi(splitPath.number) + if err != nil { + return + } + + splitPath.number = fmt.Sprintf("%0*d", length, asInt+1) +} + +func (splitPath *splitPath) decrement() { + length := len(splitPath.number) + + asInt, err := strconv.Atoi(splitPath.number) + if err != nil { + return + } + + splitPath.number = fmt.Sprintf("%0*d", length, asInt-1) +} + +func split(path string, regexes *regexes) (*splitPath, int, error) { + p := splitPath{} + + split := regexes.filename.FindAllStringSubmatch(path, -1) + + if len(split) < 1 || len(split[0]) < 3 { + return &splitPath{}, 0, nil + } + + p.base = split[0][1] + + p.number = split[0][2] + + p.extension = split[0][3] + + return &p, len(p.number), nil +}