feat: add support for enviroments

This commit is contained in:
Daniel Thomas 2022-02-17 10:29:36 +01:00
parent 7b6eacc190
commit d11acea542
2 changed files with 8 additions and 4 deletions

View File

@ -68,12 +68,15 @@ func getContentTypes(CMA *contentful.Contentful, spaceID string) (contentTypes [
return
}
func getData(spaceID, cmaKey string, flagContentTypes []string) (
func getData(spaceID, cmaKey, env string, flagContentTypes []string) (
finalContentTypes []ContentType, locales []Locale, err error,
) {
// Get client
CMA := contentful.NewCMA(cmaKey)
CMA.Debug = false
if env != "" {
CMA.Environment = env
}
// Get space locales
locales, errGetLocales := getLocales(CMA, spaceID)
@ -108,8 +111,8 @@ func getData(spaceID, cmaKey string, flagContentTypes []string) (
}
// GenerateAPI calls the generators
func GenerateAPI(dir, packageName, spaceID, cmaKey string, flagContentTypes []string) (err error) {
contentTypes, locales, errGetData := getData(spaceID, cmaKey, flagContentTypes)
func GenerateAPI(dir, packageName, spaceID, cmaKey, env string, flagContentTypes []string) (err error) {
contentTypes, locales, errGetData := getData(spaceID, cmaKey, env, flagContentTypes)
if errGetData != nil {
return errGetData
}

View File

@ -35,6 +35,7 @@ func main() {
// Get parameters from cmd line flags
flagSpaceID := flag.String("spaceid", "", "Contentful space ID")
flagCMAKey := flag.String("cmakey", "", "Contentful CMA key")
flagEnv := flag.String("env", "", "Contentful enviroment")
flagContentTypes := flag.String("contenttypes", "", "[Optional] Content type IDs to parse, comma separated")
flagVersion := flag.Bool("version", false, "Print version and exit")
flagHelp := flag.Bool("help", false, "Print version and exit")
@ -75,7 +76,7 @@ func main() {
}
}
err = erm.GenerateAPI(filepath.Dir(path), packageName, *flagSpaceID, *flagCMAKey, flagContentTypesSlice)
err = erm.GenerateAPI(filepath.Dir(path), packageName, *flagSpaceID, *flagCMAKey, *flagEnv, flagContentTypesSlice)
if err != nil {
fatal("Something went horribly wrong...", err)
}