From b16ee29f74131477072f305201ddbf3f57b58323 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Tue, 5 Dec 2023 09:42:59 +0000 Subject: [PATCH] feat(proxy): clean up root param set/root inputs (#48) --- src/app/command/bootstrap.go | 7 ++++--- src/app/command/shrink-cmd.go | 2 +- src/app/proxy/enter-root.go | 7 +++---- src/app/proxy/enter-shrink.go | 2 +- src/app/proxy/entry-base.go | 27 +++++++++++++++++---------- src/app/proxy/general-params.go | 5 ----- src/app/proxy/image-defs.go | 9 +++------ 7 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/app/command/bootstrap.go b/src/app/command/bootstrap.go index 3865802..ff2033e 100644 --- a/src/app/command/bootstrap.go +++ b/src/app/command/bootstrap.go @@ -124,12 +124,13 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command { inputs := b.getRootInputs() inputs.ParamSet.Native.Directory = proxy.ResolvePath(args[0]) - if inputs.ParamSet.Native.CPU { - inputs.ParamSet.Native.NoW = 0 + + if inputs.WorkerPoolFam.Native.CPU { + inputs.WorkerPoolFam.Native.NoWorkers = 0 } profile := inputs.ProfileFam.Native.Profile - if err := inputs.ParamSet.Native.ValidateProfile(profile, b.profiles); err != nil { + if err := b.profiles.Validate(profile); err != nil { return err } diff --git a/src/app/command/shrink-cmd.go b/src/app/command/shrink-cmd.go index fdd8822..dfe659e 100644 --- a/src/app/command/shrink-cmd.go +++ b/src/app/command/shrink-cmd.go @@ -127,7 +127,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob // validate the profile // profile := inputs.RootInputs.ProfileFam.Native.Profile - if err := inputs.RootInputs.ParamSet.Native.ValidateProfile(profile, b.profiles); err != nil { + if err := b.profiles.Validate(profile); err != nil { return err } diff --git a/src/app/proxy/enter-root.go b/src/app/proxy/enter-root.go index 90f6f7f..501d840 100644 --- a/src/app/proxy/enter-root.go +++ b/src/app/proxy/enter-root.go @@ -5,7 +5,6 @@ import ( "path/filepath" "github.com/samber/lo" - "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/configuration" "github.com/snivilised/extendio/xfs/nav" "github.com/snivilised/lorax/boost" @@ -72,7 +71,7 @@ func (e *RootEntry) ConfigureOptions(o *nav.TraverseOptions) { } func (e *RootEntry) run() error { - runnerWith := composeWith(e.Inputs.ParamSet) + runnerWith := composeWith(e.Inputs) // root does not need to support resume // @@ -101,10 +100,10 @@ func (e *RootEntry) run() error { ) } -func composeWith(rps *assistant.ParamSet[RootParameterSet]) nav.CreateNewRunnerWith { +func composeWith(inputs *RootCommandInputs) nav.CreateNewRunnerWith { with := nav.RunnerDefault - if rps.Native.CPU || rps.Native.NoW >= 0 { + if inputs.WorkerPoolFam.Native.CPU || inputs.WorkerPoolFam.Native.NoWorkers >= 0 { with |= nav.RunnerWithPool } diff --git a/src/app/proxy/enter-shrink.go b/src/app/proxy/enter-shrink.go index c13505e..8c8993c 100644 --- a/src/app/proxy/enter-shrink.go +++ b/src/app/proxy/enter-shrink.go @@ -151,7 +151,7 @@ func (e *ShrinkEntry) run(config configuration.ViperConfig) error { e.readProfile3rdPartyFlags(), ) - runnerWith := composeWith(e.Inputs.RootInputs.ParamSet) + runnerWith := composeWith(e.Inputs.RootInputs) resumption := &nav.Resumption{ // actually, we need to come up with a convenient way for the restore // file to be found. Let's assume we declare a specific location for diff --git a/src/app/proxy/entry-base.go b/src/app/proxy/entry-base.go index bf1022e..1aa2791 100644 --- a/src/app/proxy/entry-base.go +++ b/src/app/proxy/entry-base.go @@ -46,28 +46,34 @@ func (e *EntryBase) ConfigureOptions(o *nav.TraverseOptions) { // file filters, we need to define a custom compound // filter. // + switch { - case e.Inputs.ParamSet.Native.FilesGlob != "": + case e.Inputs.FoldersFam.Native.FoldersGlob != "": + pattern := e.Inputs.FoldersFam.Native.FoldersGlob o.Store.FilterDefs = &nav.FilterDefinitions{ Node: nav.FilterDef{ Type: nav.FilterTypeGlobEn, - Description: fmt.Sprintf("--files-gb(G): '%v'", e.Inputs.ParamSet.Native.FilesGlob), - Pattern: e.Inputs.ParamSet.Native.FilesGlob, + Description: fmt.Sprintf("--folders-gb(Z): '%v'", pattern), + Pattern: pattern, Scope: nav.ScopeFileEn, }, } - case e.Inputs.ParamSet.Native.FilesRexEx != "": + case e.Inputs.FoldersFam.Native.FoldersRexEx != "": + pattern := e.Inputs.FoldersFam.Native.FoldersRexEx o.Store.FilterDefs = &nav.FilterDefinitions{ Node: nav.FilterDef{ Type: nav.FilterTypeRegexEn, - Description: fmt.Sprintf("--files-rx(X): '%v'", e.Inputs.ParamSet.Native.FilesRexEx), - Pattern: e.Inputs.ParamSet.Native.FilesRexEx, + Description: fmt.Sprintf("--folders-rx(Y): '%v'", pattern), + Pattern: pattern, Scope: nav.ScopeFileEn, }, } default: + // TODO: there is still confusion here. Why do we need to set up + // a default image filter in base, when base is only interested in folders? + // shouldn't this default just be in shrink, which is interested in files. filterType := nav.FilterTypeRegexEn description := "Default image types supported by pixa" pattern := "\\.(jpe?g|png)$" @@ -116,11 +122,12 @@ func ResolvePath(path string) string { } func (e *EntryBase) readProfile3rdPartyFlags() cobrass.ThirdPartyCommandLine { - fmt.Printf("------> 💦💦💦 readProfile3rdPartyFlags: '%v'\n", e.Inputs.ParamSet.Native.Profile) + profile := e.Inputs.ProfileFam.Native.Profile + fmt.Printf("------> 💦💦💦 readProfile3rdPartyFlags: '%v'\n", profile) - return lo.TernaryF(e.Inputs.ParamSet.Native.Profile != "", + return lo.TernaryF(profile != "", func() []string { - configPath := "profiles." + e.Inputs.ParamSet.Native.Profile + configPath := "profiles." + profile return e.Config.GetStringSlice(configPath) }, func() []string { @@ -150,7 +157,7 @@ func (e *EntryBase) navigate( AccelerationInfo: &nav.Acceleration{ WgAn: wgan, RoutineName: navigatorRoutineName, - NoW: e.Inputs.ParamSet.Native.NoW, + NoW: e.Inputs.WorkerPoolFam.Native.NoWorkers, JobsChOut: make(boost.JobStream[nav.TraverseItemInput], DefaultJobsChSize), }, } diff --git a/src/app/proxy/general-params.go b/src/app/proxy/general-params.go index 958f67c..8f61335 100644 --- a/src/app/proxy/general-params.go +++ b/src/app/proxy/general-params.go @@ -1,10 +1,5 @@ package proxy -type GeneralParameters struct { - NoW int - Profile string -} - type FilterParameters struct { FolderRexEx string FolderGlob string diff --git a/src/app/proxy/image-defs.go b/src/app/proxy/image-defs.go index a54454f..831bf96 100644 --- a/src/app/proxy/image-defs.go +++ b/src/app/proxy/image-defs.go @@ -9,18 +9,15 @@ import ( ) type RootParameterSet struct { // should contain RootCommandInputs - GeneralParameters // is this wrong?, it should come from family - FilterParameters Directory string - CPU bool - Language string + Language string // TODO: move this to family store } type ConfiguredProfiles map[string][]string -func (ps *RootParameterSet) ValidateProfile(profile string, profiles ConfiguredProfiles) error { +func (ps ConfiguredProfiles) Validate(profile string) error { if profile != "" { - if _, found := profiles[profile]; !found { + if _, found := ps[profile]; !found { return fmt.Errorf("no such profile: '%v'", profile) } }