github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/test/scripts/cmd/dependencies/manager.go (about)

     1  package dependencies
     2  
     3  type dependency interface {
     4  	update() error
     5  }
     6  
     7  // Manager is the type with knowledge about how to handle dependencies.
     8  type Manager struct {
     9  	cfg *Config
    10  }
    11  
    12  // Config has the configurations options for all the updaters.
    13  type Config struct {
    14  	Images *ImagesConfig
    15  	PB     *PBConfig
    16  	TV     *TVConfig
    17  }
    18  
    19  // NewManager is the Manager constructor.
    20  func NewManager(cfg *Config) *Manager {
    21  	return &Manager{
    22  		cfg: cfg,
    23  	}
    24  }
    25  
    26  // Run is the main entry point, it executes all the configured dependency
    27  // updates.
    28  func (m *Manager) Run() error {
    29  	iu := newImageUpdater(m.cfg.Images.Names, m.cfg.Images.TargetFilePath)
    30  	pb := newPBUpdater(m.cfg.PB.SourceRepo, m.cfg.PB.TargetDirPath)
    31  	tv := newTestVectorUpdater(m.cfg.TV.SourceRepo, m.cfg.TV.TargetDirPath)
    32  
    33  	for _, dep := range []dependency{iu, pb, tv} {
    34  		if err := dep.update(); err != nil {
    35  			return err
    36  		}
    37  	}
    38  	return nil
    39  }