Skip to content

Commit

Permalink
feat(proxy): clean up root param set/root inputs (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Dec 5, 2023
1 parent 42da22f commit b16ee29
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
7 changes: 4 additions & 3 deletions src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 3 additions & 4 deletions src/app/proxy/enter-root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/proxy/enter-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 17 additions & 10 deletions src/app/proxy/entry-base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)$"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
},
}
Expand Down
5 changes: 0 additions & 5 deletions src/app/proxy/general-params.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package proxy

type GeneralParameters struct {
NoW int
Profile string
}

type FilterParameters struct {
FolderRexEx string
FolderGlob string
Expand Down
9 changes: 3 additions & 6 deletions src/app/proxy/image-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit b16ee29

Please sign in to comment.