Skip to content

Commit

Permalink
fix(proxy): re-repair existing path-finder-tests (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Feb 22, 2024
1 parent 01e40bf commit 16cae0b
Show file tree
Hide file tree
Showing 14 changed files with 1,308 additions and 792 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"mohae",
"nakedret",
"natefinch",
"navi",
"nolint",
"nolintlint",
"nosec",
Expand Down
18 changes: 12 additions & 6 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
defaultOutputPath,
),
&paramSet.Native.OutputPath, func(s string, f *pflag.Flag) error {
if f.Changed && !b.Vfs.DirectoryExists(s) {
return i18n.NewOutputPathDoesNotExistError(s)
}
// Instead of doing the commented out check, check that the location
// specified has the correct permission to write
//
// if f.Changed && !b.Vfs.DirectoryExists(s) {
// return i18n.NewOutputPathDoesNotExistError(s)
// }

return nil
},
Expand All @@ -191,9 +194,12 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
defaultTrashPath,
),
&paramSet.Native.TrashPath, func(s string, f *pflag.Flag) error {
if f.Changed && !b.Vfs.DirectoryExists(s) {
return i18n.NewOutputPathDoesNotExistError(s)
}
// Instead of doing the commented out check, check that the location
// specified has the correct permission to write
//
// if f.Changed && !b.Vfs.DirectoryExists(s) {
// return i18n.NewOutputPathDoesNotExistError(s)
// }

return nil
},
Expand Down
5 changes: 3 additions & 2 deletions src/app/proxy/enter-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func EnterShrink(
schemes := params.Inputs.Root.Configs.Schemes
selectedScheme := params.Inputs.Root.ProfileFam.Native.Scheme
scheme, _ := schemes.Scheme(selectedScheme)
noProfiles := lo.TernaryF(scheme == nil,
arity := lo.TernaryF(scheme == nil,
func() uint {
return 1
},
Expand All @@ -187,7 +187,7 @@ func EnterShrink(
OutputPath: params.Inputs.ParamSet.Native.OutputPath,
TrashPath: params.Inputs.ParamSet.Native.TrashPath,
Observer: params.Inputs.Root.Observers.PathFinder,
Arity: noProfiles,
Arity: arity,
})
fileManager := filing.NewManager(params.Vfs, finder,
params.Inputs.Root.PreviewFam.Native.DryRun,
Expand Down Expand Up @@ -220,6 +220,7 @@ func EnterShrink(
interaction := user.NewInteraction(
params.Inputs,
params.Logger,
arity,
)
entry := &ShrinkEntry{
EntryBase: EntryBase{
Expand Down
19 changes: 4 additions & 15 deletions src/app/proxy/entry-base.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log/slog"
"os"
"strings"
"time"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/assistant/configuration"
Expand All @@ -18,20 +17,6 @@ import (
"github.com/snivilised/pixa/src/app/proxy/orc"
)

func summariseAfter(result *nav.TraverseResult, err error) {
measure := fmt.Sprintf("started: '%v', elapsed: '%v'",
result.Session.StartedAt().Format(time.RFC1123), result.Session.Elapsed(),
)
files := result.Metrics.Count(nav.MetricNoFilesInvokedEn)
folders := result.Metrics.Count(nav.MetricNoFoldersInvokedEn)
summary := fmt.Sprintf("files: %v, folders: %v", files, folders)
message := lo.Ternary(err == nil,
fmt.Sprintf("🚩 navigation completed ok (%v) 💝 [%v]", summary, measure),
fmt.Sprintf("🚩 error occurred during navigation (%v)💔 [%v]", err, measure),
)
fmt.Println(message)
}

// EntryBase is the base entry for all commands in pixa
type EntryBase struct {
// some parts of the struct should go into a TraverseBase (anything to with
Expand Down Expand Up @@ -78,6 +63,10 @@ func (e *EntryBase) ConfigureOptions(o *nav.TraverseOptions) {
}), nil
}

o.Hooks.Extend = func(navi *nav.NavigationInfo, entries *nav.DirectoryContents) {
nav.DefaultExtendHookFn(navi, entries)
}

if o.Store.FilterDefs == nil {
switch {
case e.Inputs.FoldersFam.Native.FoldersGlob != "":
Expand Down
20 changes: 19 additions & 1 deletion src/app/proxy/filing/path-finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (f *PathFinder) Scheme() string {
func (f *PathFinder) Transfer(info *common.PathInfo) (folder, file string) {
folder = func() string {
if info.Cuddle {
return info.Origin // should we return empty string here?
return info.Origin
}

if info.Output != "" && info.Trash == "" {
Expand Down Expand Up @@ -278,6 +278,14 @@ func (f *PathFinder) Transfer(info *common.PathInfo) (folder, file string) {
return info.Item.Extension.Name
}()

if filepath.Join(folder, file) == info.Item.Path {
// Since we have derived a path that is the same as the input,
// we should return nothing to indicate to the file manager
// that it does not have to move/rename the input.
//
return "", ""
}

return folder, file
}

Expand Down Expand Up @@ -351,6 +359,16 @@ func (f *PathFinder) Result(info *common.PathInfo) (folder, file string) {
// The file name just matches the input file name. The folder name
// provides the context.
//
if info.Cuddle {
// decorate the input file to get the result file
//
supp := f.fileProfileSupplement(info.Profile)

return SupplementFilename(
info.Item.Extension.Name, supp, f.Stats,
)
}

return info.Item.Extension.Name
}()

Expand Down
Loading

0 comments on commit 16cae0b

Please sign in to comment.