Skip to content

Commit

Permalink
fix(command,cfg,proxy): correct processing of paths by path-finder (#172
Browse files Browse the repository at this point in the history
)

fix(proxy): minor renames (#172)

fix(proxy): add path finder observer (#172)

fix(cfg,proxy): start off stricter path finder tests (#172)

fix(command,proxy): add --cuddle flag (#172)

fix(proxy): add path-fnder unit tests (#172)

fix(proxy): add transparent/profile/non-cuddled path finder tests (#172)

fix(proxy): add transparent/profile/cuddled path finder tests (#172)

fix(proxy): add transparent/scheme path finder tests (#172)

fix(command): make cuddle incompatible with both trash and output (#172)

fix(proxy): add transparent with trash path finder unit tests (#172)

fix(proxy): non transparent with output path finder unit tests (#172)
  • Loading branch information
plastikfan committed Feb 17, 2024
1 parent 4a8068c commit 9d15bf0
Show file tree
Hide file tree
Showing 26 changed files with 1,240 additions and 229 deletions.
1 change: 1 addition & 0 deletions src/app/cfg/default-pixa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ advanced:
journal-suffix: journal
trash: TRASH
fake: .FAKE
supplement: SUPP
extensions:
suffixes-csv: "jpg,jpeg,png"
transforms-csv: lower
Expand Down
15 changes: 10 additions & 5 deletions src/app/cfg/ms-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ func (c *MsSamplerConfig) NoFolders() uint {
}

type MsLabelsConfig struct {
Adhoc string `mapstructure:"adhoc"`
Journal string `mapstructure:"journal-suffix"`
Legacy string `mapstructure:"legacy"`
Trash string `mapstructure:"trash"`
Fake string `mapstructure:"fake"`
Adhoc string `mapstructure:"adhoc"`
Journal string `mapstructure:"journal-suffix"`
Legacy string `mapstructure:"legacy"`
Trash string `mapstructure:"trash"`
Fake string `mapstructure:"fake"`
Supplement string `mapstructure:"supplement"`
}

type MsExtensionsConfig struct {
Expand Down Expand Up @@ -160,6 +161,10 @@ func (c *MsAdvancedConfig) FakeLabel() string {
return c.LabelsCFG.Fake
}

func (c *MsAdvancedConfig) SupplementLabel() string {
return c.LabelsCFG.Supplement
}

func (c *MsAdvancedConfig) Extensions() common.ExtensionsConfig {
return &c.ExtensionsCFG
}
Expand Down
1 change: 1 addition & 0 deletions src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Bootstrap struct {
Vfs storage.VirtualFS
Logger *slog.Logger
Presentation common.PresentationOptions
Observers common.Observers
}

type ConfigureOptionsInfo struct {
Expand Down
1 change: 1 addition & 0 deletions src/app/command/root-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@ func (b *Bootstrap) getRootInputs() *common.RootCommandInputs {
).(*assistant.ParamSet[store.CascadeParameterSet]),
Configs: b.Configs,
Presentation: &b.Presentation,
Observers: &b.Observers,
}
}
30 changes: 30 additions & 0 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var shrinkShortFlags = cobrass.KnownByCollection{
//
"output": "o",
"trash": "t",
"cuddle": "c",
// families:
//
"cpu": "C", // family: worker-pool
Expand Down Expand Up @@ -198,6 +199,20 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
},
)

// --cuddle(c)
//
const (
defaultCuddle = false
)

paramSet.BindBool(
newShrinkFlagInfoWithShort(
xi18n.Text(i18n.ShrinkCmdCuddleParamUsageTemplData{}),
defaultCuddle,
),
&paramSet.Native.Cuddle,
)

// --gaussian-blur(b)
//
const (
Expand Down Expand Up @@ -333,6 +348,21 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
//
// shrinkCommand.Args = validatePositionalArgs

// If we allowed --output to be specified with --cuddle, then that would
// mean the result files would be written to the output location and then input
// files would have to follow the results, leaving the origin without
// the input or the output. This could be seen as excessive and unnecessary.
// The cuddle option is most useful to the user when running a sample to
// enable easier comparison of the result with the input. If the user
// really wants to cuddle, then there should be no need to specify an output.
// We need to reduce the number of permutations to reduce complexity and
// the number of required unit tests; particularly for the path-finder.
// The same logic applies to cuddle with trash, except that's its even more
// acute in this usage scenario, because you never want your new results
// to be cuddled into the trash location.
paramSet.Command.MarkFlagsMutuallyExclusive("output", "cuddle")
paramSet.Command.MarkFlagsMutuallyExclusive("trash", "cuddle")

return shrinkCommand
}

Expand Down
71 changes: 62 additions & 9 deletions src/app/command/shrink-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ type commandTE struct {
outputFlag string
outputValue string
configPath string
expectError bool
}

type shrinkTE struct {
commandTE
directory string
}

func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root string) {
func assertShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root string) {
bootstrap := command.Bootstrap{
Vfs: vfs,
}
Expand Down Expand Up @@ -69,9 +70,16 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root
}

_, err := tester.Execute()
Expect(err).Error().To(BeNil(),
"should pass validation due to all flag being valid",
)

if entry.expectError {
Expect(err).Error().NotTo(BeNil(),
"expected error due to invalid flag combination",
)
} else {
Expect(err).Error().To(BeNil(),
"should pass validation due to all flag being valid",
)
}
}

var _ = Describe("ShrinkCmd", Ordered, func() {
Expand Down Expand Up @@ -99,12 +107,17 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
func(entry *shrinkTE) {
entry.directory = BackyardWorldsPlanet9Scan01
entry.configPath = configPath
expectValidShrinkCmdInvocation(vfs, entry, root)

assertShrinkCmdInvocation(vfs, entry, root)
},
func(entry *shrinkTE) string {
return fmt.Sprintf("🧪 ===> given: '%v'", entry.message)
},

// vanilla in this context just means that other options
// such as "--strip", "--interlace", "plane", "--quality", "85",
// are provided, in addition to the option being tested

Entry(nil, &shrinkTE{
commandTE: commandTE{
message: "vanilla with long form options",
Expand Down Expand Up @@ -218,6 +231,46 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
},
}),

// ---->
Entry(nil, &shrinkTE{
commandTE: commandTE{
message: "long form cuddle",
args: []string{
"--cuddle",
},
},
}),

Entry(nil, &shrinkTE{
commandTE: commandTE{
message: "short form cuddle",
args: []string{
"-c",
},
},
}),

Entry(nil, &shrinkTE{
commandTE: commandTE{
message: "expect error since cuddle not compatible with output",
expectError: true,
args: []string{
"--cuddle", "--output", "results",
},
},
}),

Entry(nil, &shrinkTE{
commandTE: commandTE{
message: "expect error since cuddle not compatible with trash",
expectError: true,
args: []string{
"--cuddle", "--trash", "results",
},
},
}),
// <----
)

// NB: these tests are required because state does not work with
Expand All @@ -236,7 +289,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
assertShrinkCmdInvocation(vfs, entry, root)
})

It("🧪 should: execute successfully", func() {
Expand All @@ -251,7 +304,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
assertShrinkCmdInvocation(vfs, entry, root)
})
})

Expand All @@ -268,7 +321,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
assertShrinkCmdInvocation(vfs, entry, root)
})

It("🧪 should: execute successfully", func() {
Expand All @@ -283,7 +336,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
assertShrinkCmdInvocation(vfs, entry, root)
})
})
})
1 change: 1 addition & 0 deletions src/app/proxy/common/config-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type (
LegacyLabel() string
TrashLabel() string
FakeLabel() string
SupplementLabel() string
Extensions() ExtensionsConfig
Executable() ExecutableConfig
}
Expand Down
10 changes: 4 additions & 6 deletions src/app/proxy/common/const-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ type (
}

filingDefs struct {
DejaVu string
JournalExt string
JournalTag string
JournalExt string
Discriminator string // helps to identify files that should be filtered out
}

definitions struct {
Expand Down Expand Up @@ -93,8 +92,7 @@ var Definitions = definitions{
Home: "PIXA_HOME",
},
Filing: filingDefs{
DejaVu: fmt.Sprintf("$%v$", appName),
JournalExt: ".txt",
JournalTag: ".$",
JournalExt: ".txt",
Discriminator: ".$",
},
}
14 changes: 9 additions & 5 deletions src/app/proxy/common/filing-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

type (
JournalMetaInfo struct {
Core string // without any decoration
Journal string // used as part of the journal file name
WithoutExt string
Extension string // .txt
Tag string // the journal file discriminator (.$)
Core string // without any decoration
Actual string // used as part of the journal file name
WithoutExt string
Extension string // .txt
Discriminator string // the journal/sample file discriminator (.$)
}

PathInfo struct {
Expand All @@ -21,6 +21,9 @@ type (
Scheme string
Profile string
RunStep RunStepInfo
Cuddle bool
Output string
Trash string
}

PathFinder interface {
Expand All @@ -30,6 +33,7 @@ type (
JournalFullPath(item *nav.TraverseItem) string
Statics() *StaticInfo
Scheme() string
Observe(o PathFinder) PathFinder
}

FileManager interface {
Expand Down
6 changes: 6 additions & 0 deletions src/app/proxy/common/input-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ type ShrinkParameterSet struct {
//
OutputPath string
TrashPath string
Cuddle bool
}

type Observers struct {
PathFinder PathFinder
}

type RootCommandInputs struct {
Expand All @@ -100,6 +105,7 @@ type RootCommandInputs struct {
TextualFam *assistant.ParamSet[store.TextualInteractionParameterSet]
Configs *Configs
Presentation *PresentationOptions
Observers *Observers
}

type ShrinkCommandInputs struct {
Expand Down
23 changes: 16 additions & 7 deletions src/app/proxy/common/static-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ import (
)

type StaticInfo struct {
Adhoc string
Meta JournalMetaInfo
Legacy string
Trash string
Fake string
Adhoc string
Journal JournalMetaInfo
Legacy string
Trash string
Fake string
Supplement string
}

func (i *StaticInfo) JournalLocation(name, parent string) string {
file := name + i.Meta.Journal
file := name + i.Journal.Actual
journalFile := filepath.Join(parent, file)

return journalFile
}

func (i *StaticInfo) JournalFilterGlob() string {
return fmt.Sprintf("*%v%v*", i.Meta.Tag, i.Meta.Core)
return fmt.Sprintf("*%v%v*", i.Journal.Discriminator, i.Journal.Core)
}

func (i *StaticInfo) JournalFilterRegex(sourcePattern, suffixesCSV string) string {
Expand All @@ -35,3 +36,11 @@ func (i *StaticInfo) JournalFilterRegex(sourcePattern, suffixesCSV string) strin
//
return fmt.Sprintf("(?i).%v.*(%v)$", sourcePattern, strings.Join(suffixes, "|"))
}

func (i *StaticInfo) FileSupplement(baseFilename, supp string) string {
return fmt.Sprintf("%v.%v", baseFilename, supp)
}

func (i *StaticInfo) TrashTag() string {
return fmt.Sprintf("$%v$", i.Trash)
}
Loading

0 comments on commit 9d15bf0

Please sign in to comment.