Skip to content

Commit

Permalink
chore(deps): incoming breaking changes from extendio & cobrass (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Dec 12, 2023
1 parent 11fbe2f commit dff5509
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 164 deletions.
40 changes: 22 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,56 @@ module github.com/snivilised/pixa
go 1.21

require (
github.com/onsi/ginkgo/v2 v2.13.1
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/gomega v1.30.0
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.38.1
github.com/snivilised/extendio v0.4.0
github.com/samber/lo v1.39.0
github.com/snivilised/extendio v0.5.0
github.com/snivilised/lorax v0.4.2
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.1
go.uber.org/zap v1.26.0
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/avfs/avfs v0.33.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20230406165453-00490a63f317 // indirect
github.com/google/pprof v0.0.0-20231212022811-ec68065c825e // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
golang.org/x/tools v0.16.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)

require (
github.com/cubiest/jibberjabber v1.0.1
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/nicksnyder/go-i18n/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/snivilised/cobrass v0.3.6
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/nicksnyder/go-i18n/v2 v2.3.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/snivilised/cobrass v0.4.0
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/subosito/gotenv v1.6.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
45 changes: 45 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (b *Bootstrap) viper() {

for profile, pv := range profiles {
if pair, ok := pv.(proxy.ProfilesFlagOptionAsAnyPair); ok {
b.ProfilesCFG[profile] = make(clif.SpecifiedFlagsCollection)
b.ProfilesCFG[profile] = make(clif.ChangedFlagsMap)

for flag, optionAsAny := range pair {
b.ProfilesCFG[profile][flag] = fmt.Sprint(optionAsAny)
Expand Down
2 changes: 1 addition & 1 deletion src/app/command/root-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (b *Bootstrap) buildRootCommand(container *assistant.CobraContainer) {
foldersFam := assistant.NewParamSet[store.FoldersFilterParameterSet](rootCommand)
foldersFam.Native.BindAll(foldersFam)

// family: profile [--profile(p)]
// family: profile [--profile(P), --scheme(S)]
//
profileFam := assistant.NewParamSet[store.ProfileParameterSet](rootCommand)
profileFam.Native.BindAll(profileFam, rootCommand.PersistentFlags())
Expand Down
96 changes: 28 additions & 68 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package command

import (
"fmt"
"maps"
"strings"

"github.com/samber/lo"
"github.com/snivilised/cobrass"
"github.com/snivilised/cobrass/src/assistant"
"github.com/snivilised/cobrass/src/store"
Expand All @@ -30,18 +30,22 @@ import (
// and we use capitals for the short forms of files filters, to denote
// compound filter. If files filter was not compound, it would be named
// file and the short forms would be x and g instead of X and G.
var shrinkShortFlags = cobrass.KnownByCollection{
// shrink specific:
//
"mirror-path": "r",
"mode": "m",

var thirdPartyFlags = cobrass.KnownByCollection{
// third-party:
//
"gaussian-blur": "b",
"sampling-factor": "f",
"interlace": "i",
"strip": "s",
"quality": "q",
}

var shrinkShortFlags = cobrass.KnownByCollection{
// shrink specific:
//
"mirror-path": "r",
"mode": "m",
// root:
//
"cpu": "C",
Expand All @@ -55,6 +59,10 @@ var shrinkShortFlags = cobrass.KnownByCollection{
"scheme": "S",
}

func init() {
maps.Copy(shrinkShortFlags, thirdPartyFlags)
}

const (
shrinkPsName = "shrink-ps"
filesFamName = "files-family"
Expand All @@ -67,29 +75,6 @@ func newShrinkFlagInfoWithShort[T any](usage string, defaultValue T) *assistant.
return assistant.NewFlagInfo(usage, short, defaultValue)
}

func GetThirdPartyCL(
flagSet *pflag.FlagSet,
knownBy cobrass.KnownByCollection,
changedOnly bool,
) cobrass.ThirdPartyCommandLine {
// move to cobrass/clif
//
cl := cobrass.ThirdPartyCommandLine{}

flagSet.Visit(func(f *pflag.Flag) {
if _, found := knownBy[f.Name]; found {
if !changedOnly || (changedOnly && f.Changed) {
cl = append(cl, fmt.Sprintf("--%v", f.Name))
if f.Value.Type() != "bool" {
cl = append(cl, f.Value.String())
}
}
}
})

return cl
}

type shrinkParameterSetPtr = *assistant.ParamSet[proxy.ShrinkParameterSet]

func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cobra.Command {
Expand All @@ -116,11 +101,9 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
return nil
}); xvErr == nil {
flagSet := cmd.Flags()

changed := GetThirdPartyCL(
changed := assistant.GetThirdPartyCL(
flagSet,
shrinkPS.Native.ThirdPartySet.KnownBy,
true,
)

shrinkPS.Native.ThirdPartySet.LongChangedCL = changed
Expand All @@ -130,23 +113,23 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
)

inputs := b.getShrinkInputs()
inputs.RootInputs.ParamSet.Native.Directory = helpers.ResolvePath(args[0])
inputs.Root.ParamSet.Native.Directory = helpers.ResolvePath(args[0])

// validate the profile
//
profile := inputs.RootInputs.ProfileFam.Native.Profile
profile := inputs.Root.ProfileFam.Native.Profile

if err := b.ProfilesCFG.Validate(profile); err != nil {
return err
}

// validate the scheme
//
if err := b.SamplerCFG.Validate(
inputs.ParamSet.Native.Scheme,
b.ProfilesCFG,
); err != nil {
return err
if scheme := inputs.Root.ProfileFam.Native.Scheme; scheme != "" {
if err := b.SamplerCFG.Validate(
scheme,
b.ProfilesCFG,
); err != nil {
return err
}
}

// Apply fallbacks, ie user didn't specify flag on command line
Expand All @@ -157,9 +140,9 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
// that viper would fail to pick up this value, so implementing
// the fall back manually here.
//
if inputs.RootInputs.ParamSet.Native.IsSampling {
if inputs.Root.ParamSet.Native.IsSampling {
if !flagSet.Changed("no-files") && b.SamplerCFG.NoFiles > 0 {
inputs.RootInputs.ParamSet.Native.NoFiles = b.SamplerCFG.NoFiles
inputs.Root.ParamSet.Native.NoFiles = b.SamplerCFG.NoFiles
}
}

Expand Down Expand Up @@ -228,29 +211,6 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
},
)

// -- scheme(S)
//
const (
defaultScheme = ""
)

sampler := b.optionsInfo.Config.Viper.Get("sampler")

// can we validate that it is present in the config?
paramSet.BindValidatedString(
newShrinkFlagInfoWithShort(
xi18n.Text(i18n.ShrinkCmdSchemeParamUsageTemplData{}),
defaultScheme,
),
&paramSet.Native.Scheme,
func(s string, f *pflag.Flag) error {
return lo.TernaryF(sampler != nil,
func() error { return nil },
func() error { return fmt.Errorf("sampler not found (%v)", s) },
)
},
)

// --gaussian-blur(b)
//
const (
Expand Down Expand Up @@ -358,7 +318,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
filesFam := assistant.NewParamSet[store.FilesFilterParameterSet](shrinkCommand)
filesFam.Native.BindAll(filesFam)

paramSet.Native.KnownBy = shrinkShortFlags
paramSet.Native.KnownBy = thirdPartyFlags

b.viper()

Expand Down Expand Up @@ -393,7 +353,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

func (b *Bootstrap) getShrinkInputs() *proxy.ShrinkCommandInputs {
return &proxy.ShrinkCommandInputs{
RootInputs: b.getRootInputs(),
Root: b.getRootInputs(),
ParamSet: b.Container.MustGetParamSet(
shrinkPsName,
).(*assistant.ParamSet[proxy.ShrinkParameterSet]),
Expand Down
6 changes: 3 additions & 3 deletions src/app/proxy/enter-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (e *ShrinkEntry) resumeFn(item *nav.TraverseItem) error {
}

func (e *ShrinkEntry) run(_ configuration.ViperConfig) error {
runnerWith := composeWith(e.Inputs.RootInputs)
runnerWith := composeWith(e.Inputs.Root)
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 Expand Up @@ -207,11 +207,11 @@ func EnterShrink(
profilesCFG ProfilesConfig,
samplerCFG *SamplerConfig,
) error {
fmt.Printf("---> 🔊🔊 Directory: '%v'\n", inputs.RootInputs.ParamSet.Native.Directory)
fmt.Printf("---> 🔊🔊 Directory: '%v'\n", inputs.Root.ParamSet.Native.Directory)

entry := &ShrinkEntry{
EntryBase: EntryBase{
Inputs: inputs.RootInputs,
Inputs: inputs.Root,
Program: program,
Config: config,
ProfilesCFG: profilesCFG,
Expand Down
51 changes: 0 additions & 51 deletions src/app/proxy/execution-sequence.go

This file was deleted.

28 changes: 28 additions & 0 deletions src/app/proxy/execution-step.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package proxy

import (
"github.com/snivilised/cobrass/src/clif"
)

type Step interface {
Run() error
}

// magickStep knows how to combine parameters together so that the program
// can be invoked correctly; but it does not know how to compose the input
// and output file names; this is the responsibility of the runner, which uses
// the path-finder to accomplish that task.
type magickStep struct {
fileManager *FileManager
program Executor
thirdPartyCL clif.ThirdPartyCommandLine
sourcePath string
outputPath string
journalPath string
}

func (s *magickStep) Run() error {
positional := []string{s.sourcePath}

return s.program.Execute(clif.Expand(positional, s.thirdPartyCL)...)
}
Loading

0 comments on commit dff5509

Please sign in to comment.