// EffectiveApps returns all Apps that are configured in a MHConfigFile,
// optionally filtering them with given expressions. It matches them against the
// MHConfigFiles AppSourceConfigs, if their File is not overridden. Also passes
// a given logger and effective MHConfig down to them.
//
// Todo: Support more than simple names as filter. Improve the below algorithm.
EffectiveApps returns all Apps that are configured in a MHConfigFile,
optionally filtering them with given expressions. It matches them against the
MHConfigFiles AppSourceConfigs, if their File is not overridden. Also passes
a given logger and effective MHConfig down to them.

Support more than simple names as filter. Improve the below algorithm.
// EffectiveApps returns all Apps that are configured in a MHConfigFile // optionally filtering them with given expressions . It matches them against the // MHConfigFiles AppSourceConfigs if their File is not overridden . Also passes // a given logger and effective MHConfig down to them . // // Todo : Support more than simple names as filter . Improve the below algorithm .
func (c *MHConfigFile) EffectiveApps(logger *logrus.Entry, configFile string, filters []string, effectiveMHConfig MHConfig) (*Apps, error) {
	var effectiveAppSources AppSources
	var effectiveApps Apps
	for _, appSourceConfig := range c.AppSources {
		appSource, err := NewAppSource(appSourceConfig, configFile)
		if err != nil {
			return nil, err
		}
		if len(appSource.Files) == 0 {
			logger.WithField("appSource", appSource.Name).Warn("AppSource matches no files")
		}
		effectiveAppSources = append(effectiveAppSources, *appSource)
	}
	for _, appConfig := range c.Apps {
		if len(filters) == 0 {
			if appConfig.File == nil {
				if !effectiveAppSources.File(&appConfig) {
					logger.WithFields(logrus.Fields{
						"app": appConfig.Name,
					}).Error("App not found in sources")
					return nil, fmt.Errorf("App not found in sources")
				}
			}
			app, err := NewApp(logger, appConfig, effectiveMHConfig)
			if err != nil {
				return nil, err
			}
			effectiveApps = append(effectiveApps, *app)
		} else {
			for _, filter := range filters {
				if appConfig.Name == filter || appConfig.Alias == filter {
					logger.WithFields(logrus.Fields{
						"app":    appConfig.Name,
						"filter": filter,
					}).Info("App matched filter")
					if appConfig.File == nil {
						if !effectiveAppSources.File(&appConfig) {
							logger.WithFields(logrus.Fields{
								"app": appConfig.Name,
							}).Error("App not found in sources")
							return nil, fmt.Errorf("App not found in sources")
						}
					}
					app, err := NewApp(logger, appConfig, effectiveMHConfig)
					if err != nil {
						logger.WithFields(logrus.Fields{
							"app":   appConfig.Name,
							"error": err,
						}).Error("App creation failed")
						return nil, err
					}
					effectiveApps = append(effectiveApps, *app)
					break
				}
			}
		}
	}
	return &effectiveApps, nil
}
func ( c * MHConfigFile ) EffectiveApps ( logger * logrus . Entry , configFile string , filters [ ] string , effectiveMHConfig MHConfig ) ( * Apps , error ) { var effectiveAppSources AppSources var effectiveApps Apps for _ , appSourceConfig := range c . AppSources { appSource , err := NewAppSource ( appSourceConfig , configFile ) if err != nil { return nil , err } if len ( appSource . Files ) == 0 { logger . WithField ( " " , appSource . Name ) . Warn ( " " ) } effectiveAppSources = append ( effectiveAppSources , * appSource ) } for _ , appConfig := range c . Apps { if len ( filters ) == 0 { if appConfig . File == nil { if ! effectiveAppSources . File ( & appConfig ) { logger . WithFields ( logrus . Fields { " " : appConfig . Name , } ) . Error ( " " ) return nil , fmt . Errorf ( " " ) } } app , err := NewApp ( logger , appConfig , effectiveMHConfig ) if err != nil { return nil , err } effectiveApps = append ( effectiveApps , * app ) } else { for _ , filter := range filters { if appConfig . Name == filter || appConfig . Alias == filter { logger . WithFields ( logrus . Fields { " " : appConfig . Name , " " : filter , } ) . Info ( " " ) if appConfig . File == nil { if ! effectiveAppSources . File ( & appConfig ) { logger . WithFields ( logrus . Fields { " " : appConfig . Name , } ) . Error ( " " ) return nil , fmt . Errorf ( " " ) } } app , err := NewApp ( logger , appConfig , effectiveMHConfig ) if err != nil { logger . WithFields ( logrus . Fields { " " : appConfig . Name , " " : err , } ) . Error ( " " ) return nil , err } effectiveApps = append ( effectiveApps , * app ) break } } } } return & effectiveApps , nil }
EffectiveApps returns all Apps that are configured in a MHConfigFile,
optionally filtering them with given expressions.
EffectiveApps returns all Apps that are configured in a MHConfigFile optionally filtering them with given expressions .
// Build effective app sources from AppSourceConfigs defined in configuration // file. // Build effective apps from AppConfigs given in configuration file, matching // them with effective AppSources and MHConfig built above. // If no filters are defined, add the app immediately // Match the app config with configured app sources if File is not // overridden. // If filters are defined, try to match against them // Add the app only if the filter matches its Name or Alias // Match the app config with configured app sources if File is not // overridden.