in astro/cli/astro/cmd/flags.go [122:166]
func flagsFromConfig(config *conf.Project) (flags []*projectFlag) {
if config == nil {
return
}
flagMap := map[string]*projectFlag{}
for _, moduleConf := range config.Modules {
for _, variableConf := range moduleConf.Variables {
var flagName string
var flagConf conf.Flag
// Check for flag mapping in project configuration. This is a block
// in the configuration that allows users to remap variable names
// on the CLI and set a description for the --help message.
flagConf, flagConfExists := config.Flags[variableConf.Name]
if flagConfExists {
flagName = flagConf.Name
} else {
flagName = variableConf.Name
}
if flag, ok := flagMap[flagName]; ok {
// aggregate values from all variables in the config
flag.AllowedValues = uniqueStrings(append(flag.AllowedValues, variableConf.Values...))
} else {
flag := &projectFlag{
Name: flagName,
Description: flagConf.Description,
Variable: variableConf.Name,
}
flag.AllowedValues = make([]string, len(variableConf.Values))
copy(flag.AllowedValues, variableConf.Values)
flagMap[variableConf.Name] = flag
}
}
}
// return as list
for _, flag := range flagMap {
flags = append(flags, flag)
}
return flags
}