Skip to content

Commit

Permalink
feat(proxy): create magick execution agent (#124)
Browse files Browse the repository at this point in the history
feat(cfg): add executable to advanced config (#124)

feat(command): move creation of executor to entry point (#124)

feat(proxy): use execution agent (#124)
  • Loading branch information
plastikfan committed Jan 19, 2024
1 parent 30c5352 commit 9e093fa
Show file tree
Hide file tree
Showing 25 changed files with 279 additions and 130 deletions.
24 changes: 5 additions & 19 deletions src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ type Bootstrap struct {

type ConfigureOptionsInfo struct {
Detector LocaleDetector
Program proxy.Executor
Config ConfigInfo
}

Expand All @@ -105,9 +104,6 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {

b.OptionsInfo = ConfigureOptionsInfo{
Detector: &Jabber{},
Program: &ProgramExecutor{ // 💥 TEMPORARILY OVERRIDDEN WITH DUMMY
Name: "magick",
},
Config: ConfigInfo{
Name: ApplicationName,
ConfigType: "yaml",
Expand All @@ -123,26 +119,12 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
},
}

if _, err := b.OptionsInfo.Program.Look(); err != nil {
b.OptionsInfo.Program = &DummyExecutor{
Name: b.OptionsInfo.Program.ProgName(),
}
}

for _, fo := range options {
fo(&b.OptionsInfo)
}

b.configure()

// JUST TEMPORARY: make the executor the dummy for safety
//
b.OptionsInfo.Program = &DummyExecutor{
Name: "magick",
}

fmt.Printf("===> 💥💥💥 USING DUMMY EXECUTOR !!!!\n")

b.Container = assistant.NewCobraContainer(
&cobra.Command{
Use: "main",
Expand Down Expand Up @@ -175,7 +157,11 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {

// ---> execute root core
//
return proxy.EnterRoot(inputs, b.OptionsInfo.Program, b.OptionsInfo.Config.Viper)

return proxy.EnterRoot(
inputs,
b.OptionsInfo.Config.Viper,
)
},
},
)
Expand Down
3 changes: 0 additions & 3 deletions src/app/command/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ var _ = Describe("Bootstrap", Ordered, func() {
}
rootCmd := bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
co.Program = &ExecutorStub{
Name: "magick",
}
co.Config.Name = helpers.PixaConfigTestFilename
co.Config.ConfigPath = configPath
co.Config.Viper = &configuration.GlobalViperConfig{}
Expand Down
3 changes: 0 additions & 3 deletions src/app/command/magick-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ var _ = Describe("MagickCmd", Ordered, func() {
Args: []string{"mag"},
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
co.Program = &helpers.ExecutorStub{
Name: helpers.ProgName,
}
co.Config.Name = helpers.PixaConfigTestFilename
co.Config.ConfigPath = configPath
co.Config.Viper = &configuration.GlobalViperConfig{}
Expand Down
3 changes: 0 additions & 3 deletions src/app/command/root-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ var _ = Describe("RootCmd", Ordered, func() {
tester = helpers.CommandTester{
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
co.Program = &ExecutorStub{
Name: "magick",
}
co.Config.Name = helpers.PixaConfigTestFilename
co.Config.ConfigPath = configPath
}),
Expand Down
2 changes: 0 additions & 2 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var shrinkShortFlags = cobrass.KnownByCollection{
"files": "F", // family: filter
"files-gb": "G", // family: filter
"files-rx": "X", // family: filter
"folders": "F", // family: filter
"folders-gb": "Z", // family: filter
"folders-rx": "Y", // family: filter
"profile": "P", // family: profile
Expand Down Expand Up @@ -136,7 +135,6 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
appErr = proxy.EnterShrink(
&proxy.ShrinkParams{
Inputs: inputs,
Program: b.OptionsInfo.Program,
Config: b.OptionsInfo.Config.Viper,
ProfilesCFG: b.ProfilesCFG,
SchemesCFG: b.SchemesCFG,
Expand Down
3 changes: 0 additions & 3 deletions src/app/command/shrink-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root
Args: append(args, entry.args...),
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
co.Program = &ExecutorStub{
Name: helpers.ProgName,
}
co.Config.Name = helpers.PixaConfigTestFilename
co.Config.ConfigPath = entry.configPath

Expand Down
109 changes: 80 additions & 29 deletions src/app/mocks/mocks-config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/app/proxy/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *configTE,
Args: append(options, entry.args...),
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &helpers.DetectorStub{}
co.Program = &helpers.ExecutorStub{
Name: helpers.ProgName,
}
co.Config.Name = helpers.PixaConfigTestFilename
co.Config.ConfigPath = configPath
co.Config.Viper = &configuration.GlobalViperConfig{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type (
Sequence []Step
)

// executionStep 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 controller, which uses
// controllerStep uses the agent 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 controller, which uses
// the path-finder to accomplish that task.
type executionStep struct {
type controllerStep struct {
shared *SharedControllerInfo
thirdPartyCL clif.ThirdPartyCommandLine
profile string
Expand All @@ -34,17 +34,16 @@ type executionStep struct {
}

// Run
func (s *executionStep) Run(pi *pathInfo) error {
func (s *controllerStep) Run(pi *pathInfo) error {
folder, file := s.shared.finder.Result(pi)
result := filepath.Join(folder, file)
input := []string{pi.runStep.Source}
destination := filepath.Join(folder, file)

// if transparent, then we need to ask the fm to move the
// existing file out of the way. But shouldn't that already have happened
// during setup? See, which mean setup in not working properly in
// this scenario.

return s.shared.program.Execute(
clif.Expand(input, s.thirdPartyCL, result)...,
return s.shared.agent.Invoke(
s.thirdPartyCL, pi.runStep.Source, destination,
)
}
14 changes: 7 additions & 7 deletions src/app/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ func (c *controller) profileSequence(
pi *pathInfo,
) Sequence {
changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL
cl := c.composeProfileCL(pi.profile, changed)
step := &executionStep{
combined := c.composeProfileCL(pi.profile, changed)
step := &controllerStep{
shared: c.shared,
thirdPartyCL: cl,
thirdPartyCL: combined,
sourcePath: pi.item.Path,
profile: pi.profile,
outputPath: c.shared.Inputs.ParamSet.Native.OutputPath,
Expand All @@ -69,10 +69,10 @@ func (c *controller) schemeSequence(
sequence := make(Sequence, 0, len(schemeCfg.Profiles()))

for _, current := range schemeCfg.Profiles() {
cl := c.composeProfileCL(current, changed)
step := &executionStep{
combined := c.composeProfileCL(current, changed)
step := &controllerStep{
shared: c.shared,
thirdPartyCL: cl,
thirdPartyCL: combined,
sourcePath: pi.item.Path,
profile: current,
outputPath: c.shared.Inputs.ParamSet.Native.OutputPath,
Expand All @@ -88,7 +88,7 @@ func (c *controller) adhocSequence(
pi *pathInfo,
) Sequence {
changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL
step := &executionStep{
step := &controllerStep{
shared: c.shared,
thirdPartyCL: changed,
sourcePath: pi.item.Path,
Expand Down
6 changes: 0 additions & 6 deletions src/app/proxy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ var _ = Describe("SamplerController", Ordered, func() {
Args: args,
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &helpers.DetectorStub{}
co.Program = &helpers.ExecutorStub{
Name: helpers.ProgName,
}
co.Config.Name = helpers.PixaConfigTestFilename
co.Config.ConfigPath = configPath
co.Config.Viper = &configuration.GlobalViperConfig{}
Expand Down Expand Up @@ -613,9 +610,6 @@ var _ = Describe("end to end", Ordered, func() {
Args: args,
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &helpers.DetectorStub{}
co.Program = &helpers.ExecutorStub{
Name: helpers.ProgName,
}
co.Config.Name = "pixa"
co.Config.ConfigPath = configPath
}),
Expand Down
14 changes: 3 additions & 11 deletions src/app/proxy/enter-root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ type configProfile struct {
args []string
}

type Executor interface {
ProgName() string
Look() (string, error)
Execute(args ...string) error
}

const (
DefaultJobsChSize = 10
)
Expand Down Expand Up @@ -50,7 +44,7 @@ func (e *RootEntry) principalFn(item *nav.TraverseItem) error {
item.Path,
)

return e.Program.Execute("--version")
return nil
}

func (e *RootEntry) ConfigureOptions(o *nav.TraverseOptions) {
Expand Down Expand Up @@ -112,16 +106,14 @@ func composeWith(inputs *RootCommandInputs) nav.CreateNewRunnerWith {

func EnterRoot(
inputs *RootCommandInputs,
program Executor,
config configuration.ViperConfig,
) error {
fmt.Printf("---> 📁📁📁 Directory: '%v'\n", inputs.ParamSet.Native.Directory)

entry := &RootEntry{
EntryBase: EntryBase{
Inputs: inputs,
Program: program,
Config: config,
Inputs: inputs,
Config: config,
},
}

Expand Down
Loading

0 comments on commit 9e093fa

Please sign in to comment.