Skip to content

Commit

Permalink
ref(proxy): reorganise runner (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Dec 13, 2023
1 parent dff5509 commit 6d3b6d3
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 152 deletions.
5 changes: 5 additions & 0 deletions src/app/proxy/execution-step.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import (
"github.com/snivilised/cobrass/src/clif"
)

// Step
type Step interface {
Run() error
}

// Sequence
type Sequence []Step

// 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
Expand All @@ -21,6 +25,7 @@ type magickStep struct {
journalPath string
}

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

Expand Down
150 changes: 0 additions & 150 deletions src/app/proxy/item-runners.go

This file was deleted.

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

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

// 3rd party arguments provider: ad-hoc/profile/scheme
// ad-hoc: all on the fly arguments
// profile: ad-hoc and profile
// scheme: adhoc and profile from a scheme
//

type baseRunner struct {
shared *SharedRunnerInfo
}

func (r *baseRunner) profileSequence(
name, itemPath string,
) Sequence {
changed := r.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL
cl := r.composeProfileCL(name, changed)
step := &magickStep{
// fileManager
program: r.shared.program,
thirdPartyCL: cl,
sourcePath: itemPath,
// outputPath: ,
// journalPath: ,
}

return Sequence{step}
}

func (r *baseRunner) schemeSequence(
name, itemPath string,
) Sequence {
changed := r.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL
scheme := r.shared.sampler.Schemes[name]
sequence := make(Sequence, 0, len(scheme.Profiles))

for _, currentProfileName := range scheme.Profiles {
cl := r.composeProfileCL(currentProfileName, changed)
step := &magickStep{
// fileManager
program: r.shared.program,
thirdPartyCL: cl,
sourcePath: itemPath,
// outputPath: ,
// journalPath: ,
}

sequence = append(sequence, step)
}

return sequence
}

func (r *baseRunner) adhocSequence(
itemPath string,
) Sequence {
changed := r.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL
step := &magickStep{
// fileManager
program: r.shared.program,
thirdPartyCL: changed,
sourcePath: itemPath,
// outputPath: ,
// journalPath: ,
}

return Sequence{step}
}

func (r *baseRunner) composeProfileCL(
profileName string,
secondary clif.ThirdPartyCommandLine,
) clif.ThirdPartyCommandLine {
primary := r.shared.profiles[profileName]

return cobrass.Evaluate(
primary,
r.shared.Inputs.ParamSet.Native.ThirdPartySet.KnownBy,
secondary,
)
}

func (r *baseRunner) Run(sequence Sequence) error {
var (
zero Step
resultErr error
)

iterator := collections.ForwardRunIt[Step, error](sequence, zero)
each := func(s Step) error {
return s.Run()
}
while := func(_ Step, err error) bool {
if resultErr == nil {
resultErr = err
}

// this needs to change according to a new, not yet defined
// setting, 'ContinueOnError'
//
return err == nil
}

iterator.RunAll(each, while)

return resultErr
}

func (r *baseRunner) Reset() {
}
21 changes: 21 additions & 0 deletions src/app/proxy/runner-full.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package proxy

import (
"github.com/snivilised/cobrass"
"github.com/snivilised/extendio/xfs/nav"
)

type FullRunner struct {
baseRunner
}

func (r *FullRunner) OnNewShrinkItem(item *nav.TraverseItem,
positional []string,
thirdPartyCL cobrass.ThirdPartyCommandLine,
) error {
_ = item
_ = positional
_ = thirdPartyCL

return nil
}
4 changes: 2 additions & 2 deletions src/app/proxy/runner-registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ func NewRunnerRegistry(shared *SharedRunnerInfo) *RunnerRegistry {
switch shared.Type {
case RunnerTypeFullEn:
return &FullRunner{
itemRunner: itemRunner{
baseRunner: baseRunner{
shared: shared,
},
}

case RunnerTypeSamplerEn:
return &SamplerRunner{
itemRunner: itemRunner{
baseRunner: baseRunner{
shared: shared,
},
}
Expand Down
47 changes: 47 additions & 0 deletions src/app/proxy/runner-sampler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package proxy

import (
"github.com/snivilised/extendio/xfs/nav"
)

type SamplerRunner struct {
baseRunner
}

func (r *SamplerRunner) OnNewShrinkItem(item *nav.TraverseItem,
positional []string,
) error {
_ = positional

// foreach profileName inside the scheme:
// start off with (*r.shared.profilesCFG)[blurProfile] => copy into another map: current
// foreach args in secondary
// if secondary arg not present in current, add to current
// if secondary arg not present in current, if not already in current
// ---
// - at end, we end up with a map(current) that contains profileName args combined with present
// - add the current to end of positional to create a clif.ThirdPartyCommandLine: useCL
// to achieve this Overlay needs the KnownBy collection the same way Evaluate does;
// the reason is although we can limit the flags specified inside the config to be
// of their long forms, the arguments present on the command line must be free to be
// either long or short forms, therefore we, need to be able to recognise if a short form
// flag in present is actually in present in the config as its long form.
//
profileName := r.shared.Inputs.Root.ProfileFam.Native.Profile
schemeName := r.shared.Inputs.Root.ProfileFam.Native.Scheme

var sequence Sequence

switch {
case profileName != "":
sequence = r.profileSequence(profileName, item.Path)

case schemeName != "":
sequence = r.schemeSequence(schemeName, item.Path)

default:
sequence = r.adhocSequence(item.Path)
}

return r.Run(sequence)
}

0 comments on commit 6d3b6d3

Please sign in to comment.