diff --git a/src/app/command/bootstrap.go b/src/app/command/bootstrap.go index 943faba..bd97a18 100644 --- a/src/app/command/bootstrap.go +++ b/src/app/command/bootstrap.go @@ -13,6 +13,7 @@ import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/configuration" ci18n "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/clif" xi18n "github.com/snivilised/extendio/i18n" "github.com/snivilised/extendio/xfs/utils" "github.com/snivilised/pixa/src/app/proxy" @@ -132,6 +133,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command { } profile := inputs.ProfileFam.Native.Profile + if err := b.ProfilesCFG.Validate(profile); err != nil { return err } @@ -213,14 +215,33 @@ func handleLangSetting(config configuration.ViperConfig) { } func (b *Bootstrap) viper() { + b.ProfilesCFG = make(proxy.ProfilesConfig) + // Ideally, the ProfileParameterSet would perform a check against // the config, but extendio is not aware of config, so it can't // check. Instead, we can check here. // - b.ProfilesCFG = b.optionsInfo.Config.Viper.GetStringMapStringSlice("profiles") - err := b.optionsInfo.Config.Viper.UnmarshalKey("sampler", &b.SamplerCFG) - if err != nil { + raw := b.optionsInfo.Config.Viper.Get("profiles") + + if raw != nil { + profiles, ok := raw.(proxy.ProfilesFlagOptionAsAnyPair) + if !ok { + panic("Invalid type for 'profiles'") + } + + for profile, pv := range profiles { + if pair, ok := pv.(proxy.ProfilesFlagOptionAsAnyPair); ok { + b.ProfilesCFG[profile] = make(clif.SpecifiedFlagsCollection) + + for flag, optionAsAny := range pair { + b.ProfilesCFG[profile][flag] = fmt.Sprint(optionAsAny) + } + } + } + } + + if err := b.optionsInfo.Config.Viper.UnmarshalKey("sampler", &b.SamplerCFG); err != nil { panic(err) } } diff --git a/src/app/command/shrink-cmd.go b/src/app/command/shrink-cmd.go index 45a8487..f5c1508 100644 --- a/src/app/command/shrink-cmd.go +++ b/src/app/command/shrink-cmd.go @@ -100,16 +100,22 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob }); xvErr == nil { options := []string{} present := make(cobrass.SpecifiedFlagsCollection) + presentCL := cobrass.ThirdPartyCommandLine{} flagSet := cmd.Flags() flagSet.Visit(func(f *pflag.Flag) { - options = append(options, fmt.Sprintf("--%v=%v", f.Name, f.Value)) + options = append(options, fmt.Sprintf("--%v=%v [type: %v]", f.Name, f.Value, f.Value.Type())) if isThirdPartyKnown(f.Name, shrinkPS.Native.ThirdPartySet.KnownBy) { present[f.Name] = f.Value.String() + presentCL = append(presentCL, f.Name) + if f.Value.Type() != "bool" { + presentCL = append(presentCL, f.Value.String()) + } } }) shrinkPS.Native.ThirdPartySet.Present = present + shrinkPS.Native.ThirdPartySet.LongPresentCL = presentCL fmt.Printf("%v %v Running shrink, with options: '%v', args: '%v'\n", AppEmoji, ApplicationName, options, strings.Join(args, "/"), @@ -129,6 +135,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob // validate the profile // profile := inputs.RootInputs.ProfileFam.Native.Profile + if err := b.ProfilesCFG.Validate(profile); err != nil { return err } @@ -137,7 +144,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob // if err := b.SamplerCFG.Validate( inputs.ParamSet.Native.Scheme, - &b.ProfilesCFG, + b.ProfilesCFG, ); err != nil { return err } @@ -160,7 +167,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob inputs, b.optionsInfo.Program, b.optionsInfo.Config.Viper, - &b.ProfilesCFG, + b.ProfilesCFG, &b.SamplerCFG, ) } else { diff --git a/src/app/proxy/enter-shrink.go b/src/app/proxy/enter-shrink.go index 69f945c..773d718 100644 --- a/src/app/proxy/enter-shrink.go +++ b/src/app/proxy/enter-shrink.go @@ -113,16 +113,14 @@ func (e *ShrinkEntry) ConfigureOptions(o *nav.TraverseOptions) { e.EntryBase.ConfigureOptions(o) - if e.Registry == nil { - e.Registry = NewRunnerRegistry(&SharedRunnerInfo{ - Type: RunnerTypeSamplerEn, // TODO: to come from an arg !!! - Options: e.Options, - program: e.Program, - profilesCFG: e.ProfilesCFG, - samplerCFG: e.SamplerCFG, - Inputs: e.Inputs, - }) - } + e.Registry = NewRunnerRegistry(&SharedRunnerInfo{ + Type: RunnerTypeSamplerEn, // TODO: to come from an arg !!! + Options: e.Options, + program: e.Program, + profilesCFG: e.ProfilesCFG, + samplerCFG: e.SamplerCFG, + Inputs: e.Inputs, + }) } func clearResumeFromWith(with nav.CreateNewRunnerWith) nav.CreateNewRunnerWith { @@ -213,7 +211,7 @@ func EnterShrink( inputs *ShrinkCommandInputs, program Executor, config configuration.ViperConfig, - profilesCFG *ProfilesConfig, + profilesCFG ProfilesConfig, samplerCFG *SamplerConfig, ) error { fmt.Printf("---> 🔊🔊 Directory: '%v'\n", inputs.RootInputs.ParamSet.Native.Directory) diff --git a/src/app/proxy/entry-base.go b/src/app/proxy/entry-base.go index d98bd0b..0f29306 100644 --- a/src/app/proxy/entry-base.go +++ b/src/app/proxy/entry-base.go @@ -35,7 +35,7 @@ type EntryBase struct { ThirdPartyCL cobrass.ThirdPartyCommandLine Options *nav.TraverseOptions Registry *RunnerRegistry - ProfilesCFG *ProfilesConfig + ProfilesCFG ProfilesConfig SamplerCFG *SamplerConfig } diff --git a/src/app/proxy/image-defs.go b/src/app/proxy/image-defs.go index 4fbe4b9..0b19a0c 100644 --- a/src/app/proxy/image-defs.go +++ b/src/app/proxy/image-defs.go @@ -5,6 +5,7 @@ import ( "github.com/snivilised/cobrass" "github.com/snivilised/cobrass/src/assistant" + "github.com/snivilised/cobrass/src/clif" "github.com/snivilised/cobrass/src/store" ) @@ -17,11 +18,15 @@ type RootParameterSet struct { // should contain RootCommandInputs Language string // TODO: move this to family store } -type ProfilesConfig map[string][]string +type ( + ProfilesFlagOptionAsAnyPair = map[string]any + ProfilesFlagOptionPair = map[string]string + ProfilesConfig map[string]clif.SpecifiedFlagsCollection +) -func (ps ProfilesConfig) Validate(name string) error { +func (pc ProfilesConfig) Validate(name string) error { if name != "" { - if _, found := ps[name]; !found { + if _, found := pc[name]; !found { return fmt.Errorf("no such profile: '%v'", name) } } @@ -86,8 +91,9 @@ type ThirdPartySet struct { Quality int // Auxiliary // - Present cobrass.SpecifiedFlagsCollection - KnownBy cobrass.KnownByCollection + Present cobrass.SpecifiedFlagsCollection + LongPresentCL cobrass.ThirdPartyCommandLine + KnownBy cobrass.KnownByCollection } // [blur] diff --git a/src/app/proxy/item-runners.go b/src/app/proxy/item-runners.go index 5e0c4d7..861a3fc 100644 --- a/src/app/proxy/item-runners.go +++ b/src/app/proxy/item-runners.go @@ -85,6 +85,16 @@ func (r *SamplerRunner) OnNewShrinkItem(item *nav.TraverseItem, // then we invoke as: // r.shared.program.Execute(clif.Expand(positional, resultCL)...) + if profile := r.shared.Inputs.RootInputs.ProfileFam.Native.Profile; profile != "" { + secondary := r.shared.Inputs.ParamSet.Native.ThirdPartySet.LongPresentCL + eval := cobrass.Evaluate(r.shared.profilesCFG[profile], + r.shared.Inputs.ParamSet.Native.ThirdPartySet.KnownBy, + secondary, + ) + + _ = clif.Expand(positional, eval) + } + return r.shared.program.Execute(clif.Expand(positional, thirdPartyCL)...) } diff --git a/src/app/proxy/proxy-defs.go b/src/app/proxy/proxy-defs.go index f15d4a2..187617b 100644 --- a/src/app/proxy/proxy-defs.go +++ b/src/app/proxy/proxy-defs.go @@ -17,7 +17,7 @@ type SharedRunnerInfo struct { Type RunnerTypeEnum Options *nav.TraverseOptions program Executor - profilesCFG *ProfilesConfig + profilesCFG ProfilesConfig samplerCFG *SamplerConfig Inputs *ShrinkCommandInputs } diff --git a/src/app/proxy/runner-registry.go b/src/app/proxy/runner-registry.go index 5c5dc72..b76ae35 100644 --- a/src/app/proxy/runner-registry.go +++ b/src/app/proxy/runner-registry.go @@ -2,18 +2,8 @@ package proxy import ( "sync" - - "github.com/snivilised/extendio/xfs/nav" ) -type NewRunnerParams struct { - Type RunnerTypeEnum - Options *nav.TraverseOptions - Program Executor - ProfilesCFG *ProfilesConfig - SamplerCFG *SamplerConfig -} - func NewRunnerRegistry(shared *SharedRunnerInfo) *RunnerRegistry { return &RunnerRegistry{ pool: sync.Pool{ diff --git a/src/app/proxy/sampler-config.go b/src/app/proxy/sampler-config.go index 623ab7e..7d08cbb 100644 --- a/src/app/proxy/sampler-config.go +++ b/src/app/proxy/sampler-config.go @@ -18,7 +18,7 @@ type ( } ) -func (cs SamplerConfig) Validate(name string, profiles *ProfilesConfig) error { +func (cs SamplerConfig) Validate(name string, profiles ProfilesConfig) error { if name == "" { return nil } @@ -33,7 +33,7 @@ func (cs SamplerConfig) Validate(name string, profiles *ProfilesConfig) error { } for _, p := range scheme.Profiles { - if _, found := (*profiles)[p]; !found { + if _, found := profiles[p]; !found { return fmt.Errorf("profile(referenced by scheme: '%v'): '%v' not found in config", name, p, ) diff --git a/src/app/proxy/sampler-runner_test.go b/src/app/proxy/sampler-runner_test.go index e481a1d..26debbf 100644 --- a/src/app/proxy/sampler-runner_test.go +++ b/src/app/proxy/sampler-runner_test.go @@ -133,6 +133,8 @@ var _ = Describe("SamplerRunner", Ordered, func() { "--no-files", "4", "--files-gb", "*Energy-Explorers*", "--profile", "adaptive", + "--gaussian-blur", "0.51", + "--interlace", "line", }, }, }), diff --git a/test/data/configuration/pixa-test.yml b/test/data/configuration/pixa-test.yml index 2e7d191..ceae337 100644 --- a/test/data/configuration/pixa-test.yml +++ b/test/data/configuration/pixa-test.yml @@ -1,25 +1,18 @@ profiles: blur: - ["--strip", "--interlace", "plane", "--gaussian-blur", "0.05"] + strip: true + interlace: "plane" + gaussian-blur: "0.05" sf: - [ - "--dry-run", - "--strip", - "--interlace", - "plane", - "--sampling-factor", - "4:2:0", - ] + dry-run: true + strip: true + interlace: "plane" + sampling-factor: "4:2:0" adaptive: - [ - "--strip", - "--interlace", - "plane", - "--gaussian-blur", - "0.05", - "--adaptive-resize", - "60", - ] + strip: true + interlace: "plane" + gaussian-blur: "0.25" + adaptive-resize: "60" sampler: files: 2 folders: 1