@@ -51,9 +51,6 @@ type Manager interface {
5151
5252 // RenderAll renders all dependencies
5353 RenderAll (options RenderOptions ) ([]types.Dependency , error )
54-
55- // Command executes a dependency command
56- Command (options CommandOptions ) error
5754}
5855
5956type manager struct {
@@ -114,40 +111,6 @@ func (m *manager) ResolveAll(options ResolveOptions) ([]types.Dependency, error)
114111 return dependencies , nil
115112}
116113
117- // CommandOptions has all options for executing a command from a dependency
118- type CommandOptions struct {
119- Dependency string
120- Command string
121- Args []string
122- UpdateDependencies bool
123- Verbose bool
124- }
125-
126- // Command will execute a dependency command
127- func (m * manager ) Command (options CommandOptions ) error {
128- found := false
129- _ , err := m .handleDependencies (nil , []string {options .Dependency }, false , options .UpdateDependencies , true , options .Verbose , "Command" , func (dependency * Dependency , log log.Logger ) error {
130- // Switch current working directory
131- currentWorkingDirectory , err := dependency .prepare (true )
132- if err != nil {
133- return err
134- } else if currentWorkingDirectory == "" {
135- return nil
136- }
137-
138- // Change back to original working directory
139- defer func () { _ = os .Chdir (currentWorkingDirectory ) }()
140-
141- found = true
142- return ExecuteCommand (dependency .localConfig .Config ().Commands , options .Command , options .Args , os .Stdout , os .Stderr )
143- })
144- if ! found {
145- return fmt .Errorf ("couldn't find dependency %s" , options .Dependency )
146- }
147-
148- return err
149- }
150-
151114// ExecuteCommand executes a given command from the available commands
152115func ExecuteCommand (commands []* latest.CommandConfig , cmd string , args []string , stdout io.Writer , stderr io.Writer ) error {
153116 err := command .ExecuteCommand (commands , cmd , args , stdout , stderr )
@@ -389,6 +352,32 @@ func (m *manager) handleDependencies(skipDependencies, filterDependencies []stri
389352 return retDependencies , nil
390353}
391354
355+ func GetDependencyByPath (dependencies []types.Dependency , path string ) types.Dependency {
356+ splitted := strings .Split (path , "." )
357+
358+ var retDependency types.Dependency
359+ searchDependencies := dependencies
360+ for _ , segment := range splitted {
361+ var nextDependency types.Dependency
362+ for _ , dependency := range searchDependencies {
363+ if dependency .Name () == segment {
364+ nextDependency = dependency
365+ break
366+ }
367+ }
368+
369+ // not found, exit here
370+ if nextDependency == nil {
371+ return nil
372+ }
373+
374+ searchDependencies = nextDependency .Children ()
375+ retDependency = nextDependency
376+ }
377+
378+ return retDependency
379+ }
380+
392381// Dependency holds the dependency config and has an id
393382type Dependency struct {
394383 id string
@@ -429,6 +418,20 @@ func (d *Dependency) Root() bool { return d.root }
429418
430419func (d * Dependency ) BuiltImages () map [string ]string { return d .builtImages }
431420
421+ func (d * Dependency ) Command (command string , args []string ) error {
422+ // Switch current working directory
423+ currentWorkingDirectory , err := d .prepare (true )
424+ if err != nil {
425+ return err
426+ } else if currentWorkingDirectory == "" {
427+ return nil
428+ }
429+
430+ // Change back to original working directory
431+ defer func () { _ = os .Chdir (currentWorkingDirectory ) }()
432+ return ExecuteCommand (d .localConfig .Config ().Commands , command , args , os .Stdout , os .Stderr )
433+ }
434+
432435// Build builds and pushes all defined images
433436func (d * Dependency ) Build (forceDependencies bool , buildOptions * build.Options , log log.Logger ) error {
434437 // Switch current working directory
0 commit comments