Exemplo n.º 1
0
func deploymentDefaults(fs *pflag.FlagSet, f *fg.Flags, args []string) {
	// Merge Options
	fs.VisitAll(func(flag *pflag.Flag) {
		if !flag.Changed {
			value, ok := f.Options.Get(flag.Name)
			if ok {
				svalue := fmt.Sprintf("%v", value)
				err := fs.Set(flag.Name, svalue)
				if err != nil {
					Exitf("Error in option '%s': %#v\n", flag.Name, err)
				}
			}
		}
	})

	if f.Local {
		f.StopDelay = 5 * time.Second
		f.DestroyDelay = 3 * time.Second
		f.SliceDelay = 5 * time.Second
	}

	if f.JobPath == "" && len(args) >= 1 {
		f.JobPath = args[0]
	}
	if f.ClusterPath == "" && len(args) >= 2 {
		f.ClusterPath = args[1]
	}
}
Exemplo n.º 2
0
func setFlagFromEnv(f *pflag.FlagSet, flagInfo cliflags.FlagInfo) {
	if flagInfo.EnvVar != "" {
		if value, set := envutil.EnvString(flagInfo.EnvVar, 2); set {
			if err := f.Set(flagInfo.Name, value); err != nil {
				panic(err)
			}
		}
	}
}
Exemplo n.º 3
0
// getFlagsFromEnv parses all registered flags in the given flagset,
// and if they are not already set it attempts to set their values from
// environment variables. Environment variables take the name of the flag but
// are UPPERCASE, have the given prefix, and any dashes are replaced by
// underscores - for example: some-flag => PREFIX_SOME_FLAG
func getFlagsFromEnv(prefix string, fs *pflag.FlagSet) {
	alreadySet := make(map[string]bool)
	fs.Visit(func(f *pflag.Flag) {
		alreadySet[f.Name] = true
	})
	fs.VisitAll(func(f *pflag.Flag) {
		if !alreadySet[f.Name] {
			key := strings.ToUpper(prefix + "_" + strings.Replace(f.Name, "-", "_", -1))
			val := os.Getenv(key)
			if val != "" {
				fs.Set(f.Name, val)
			}
		}

	})
}
Exemplo n.º 4
0
Arquivo: env.go Projeto: sgotti/stolon
// SetFlagsFromEnv parses all registered flags in the given flagset,
// and if they are not already set it attempts to set their values from
// environment variables. Environment variables take the name of the flag but
// are UPPERCASE, and any dashes are replaced by underscores. Environment
// variables additionally are prefixed by the given string followed by
// and underscore. For example, if prefix=PREFIX: some-flag => PREFIX_SOME_FLAG
func SetFlagsFromEnv(fs *flag.FlagSet, prefix string) (err error) {
	alreadySet := make(map[string]bool)
	fs.Visit(func(f *flag.Flag) {
		alreadySet[f.Name] = true
	})
	fs.VisitAll(func(f *flag.Flag) {
		if !alreadySet[f.Name] {
			key := prefix + "_" + strings.ToUpper(strings.Replace(f.Name, "-", "_", -1))
			val := os.Getenv(key)
			if val != "" {
				if serr := fs.Set(f.Name, val); serr != nil {
					err = fmt.Errorf("invalid value %q for %s: %v", val, key, serr)
				}
			}
		}
	})
	return err
}
Exemplo n.º 5
0
Arquivo: main.go Projeto: pulcy/quark
// loadArgumentsFromCluster and uses its data to update the given flagset.
func loadArgumentsFromCluster(flagSet *pflag.FlagSet, requireProfile bool) {
	if cluster == "" {
		return
	}
	profile := ""
	parts := strings.Split(cluster, "@")
	if len(parts) == 2 {
		profile = parts[0]
		cluster = parts[1]
	} else if requireProfile {
		Exitf("No cluster profile specified (-c profile@cluster)")
	}
	clustersPath := os.Getenv("PULCY_CLUSTERS")
	if clustersPath == "" {
		clustersPath = "config/clusters"
	}
	path, err := resolvePath(cluster, clustersPath, ".hcl")
	if err != nil {
		Exitf("Cannot resolve cluster path: %#v", err)
	}
	c, err := clusterpkg.ParseClusterFromFile(path)
	if err != nil {
		Exitf("Cannot load cluster from path '%s': %#v", clustersPath, err)
	}
	values, err := c.ResolveProfile(profile)
	if err != nil {
		Exitf("Cannot resolve profile '%s' in cluster path '%s': %#v", profile, clustersPath, err)
	}
	flagSet.VisitAll(func(flag *pflag.Flag) {
		if !flag.Changed {
			value, ok := values[flag.Name]
			if ok {
				err := flagSet.Set(flag.Name, fmt.Sprintf("%v", value))
				if err != nil {
					Exitf("Error in option '%s': %#v\n", flag.Name, err)
				}
				log.Debugf("--%s=%v", flag.Name, value)
			}
		}
	})
}