generated from snivilised/arcadia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command): implement root command (#27)
- Loading branch information
1 parent
92b35b9
commit 257b309
Showing
9 changed files
with
178 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package magick | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"path/filepath" | ||
|
||
"github.com/samber/lo" | ||
"github.com/snivilised/cobrass/src/assistant" | ||
"github.com/snivilised/extendio/xfs/nav" | ||
) | ||
|
||
type RootEntry struct { | ||
EntryBase | ||
|
||
rps *assistant.ParamSet[RootParameterSet] | ||
files []string | ||
} | ||
|
||
func (e *RootEntry) ConfigureOptions(o *nav.TraverseOptions) { | ||
o.Notify.OnBegin = func(_ *nav.NavigationState) { | ||
fmt.Printf("===> 🛡️ beginning traversal ...\n") | ||
} | ||
o.Notify.OnEnd = func(result *nav.TraverseResult) { | ||
fmt.Printf("===> 🚩 finished traversal - folders '%v'\n", | ||
result.Metrics.Count(nav.MetricNoFoldersInvokedEn), | ||
) | ||
} | ||
o.Callback = nav.LabelledTraverseCallback{ | ||
Label: "Root Entry Callback", | ||
Fn: func(item *nav.TraverseItem) error { | ||
depth := item.Extension.Depth | ||
indicator := lo.Ternary(len(item.Children) > 0, "☀️", "🌊") | ||
|
||
lo.ForEach(item.Children, func(de fs.DirEntry, index int) { | ||
fullPath := filepath.Join(item.Path, de.Name()) | ||
e.files = append(e.files, fullPath) | ||
}) | ||
|
||
fmt.Printf( | ||
"---> %v ROOT-CALLBACK: (depth:%v, files:%v) '%v'\n", | ||
indicator, | ||
depth, len(item.Children), | ||
item.Path, | ||
) | ||
|
||
return nil | ||
}, | ||
} | ||
o.Store.Subscription = nav.SubscribeFoldersWithFiles | ||
o.Store.DoExtend = true | ||
e.EntryBase.ConfigureOptions(o) | ||
} | ||
|
||
func GetRootTraverseOptionsFunc(entry *RootEntry) func(o *nav.TraverseOptions) { | ||
// make this a generic? | ||
// | ||
return func(o *nav.TraverseOptions) { | ||
entry.ConfigureOptions(o) | ||
} | ||
} | ||
|
||
func EnterRoot( | ||
rps *assistant.ParamSet[RootParameterSet], | ||
) error { | ||
fmt.Printf("---> 🦠🦠🦠 Directory: '%v'\n", rps.Native.Directory) | ||
|
||
entry := &RootEntry{ | ||
rps: rps, | ||
} | ||
session := &nav.PrimarySession{ | ||
Path: rps.Native.Directory, | ||
OptionFn: GetRootTraverseOptionsFunc(entry), | ||
} | ||
result, err := session.Init().Run() | ||
|
||
lo.ForEach(entry.files, func(f string, _ int) { | ||
fmt.Printf(" ===> 🔆 candidate file: '%v'\n", f) | ||
}) | ||
|
||
no := result.Metrics.Count(nav.MetricNoChildFilesFoundEn) | ||
summary := fmt.Sprintf("files: %v", no) | ||
message := lo.Ternary(err == nil, | ||
fmt.Sprintf("navigation completed (%v) ✔️", summary), | ||
fmt.Sprintf("error occurred during navigation (%v)❌\n", err), | ||
) | ||
fmt.Println(message) | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package magick | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/snivilised/extendio/xfs/nav" | ||
) | ||
|
||
type EntryBase struct { | ||
session nav.TraverseSession | ||
} | ||
|
||
func (e *EntryBase) ConfigureOptions(o *nav.TraverseOptions) { | ||
o.Store.FilterDefs = &nav.FilterDefinitions{ | ||
Children: nav.CompoundFilterDef{ | ||
Type: nav.FilterTypeRegexEn, | ||
Description: "Image types supported by pixa", | ||
Pattern: "\\.(jpe?g|png|gif)$", | ||
}, | ||
} | ||
} | ||
|
||
func ResolvePath(path string) string { | ||
result := path | ||
|
||
if result[0] == '~' { | ||
if h, err := os.UserHomeDir(); err == nil { | ||
result = filepath.Join(h, result[1:]) | ||
} | ||
} else { | ||
if absolute, absErr := filepath.Abs(path); absErr == nil { | ||
result = absolute | ||
} | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters