cache all content types by default, CLI improvements

This commit is contained in:
Cristian Vidmar 2021-07-08 13:16:06 +02:00
parent 1a5f0671da
commit 6a3be467c5
2 changed files with 32 additions and 10 deletions

View File

@ -362,16 +362,20 @@ func RichTextToHtml(rt interface{}, linkResolver LinkResolverFunc, entryLinkReso
func (cc *ContentfulClient) UpdateCache(ctx context.Context, contentTypes []string, cacheAssets bool) error {
start := time.Now()
if contentTypes == nil {
contentTypes = spaceContentTypes
} else {
for _, contentType := range contentTypes {
if !stringSliceContains(spaceContentTypes, contentType) {
return fmt.Errorf("UpdateCache: Content Type %q not available in this space", contentType)
}
}
}
tempCache := &ContentfulCache{
contentTypes: contentTypes,
idContentTypeMap: map[string]string{},
parentMap: map[string][]EntryReference{},
}
for _, contentType := range contentTypes {
if !stringSliceContains(spaceContentTypes, contentType) {
return fmt.Errorf("UpdateCache: Content Type %q not available in this space", contentType)
}
}
if cacheAssets {
contentTypes = append([]string{assetWorkerType}, contentTypes...)
}

28
main.go
View File

@ -11,12 +11,18 @@ import (
"github.com/foomo/gocontentful/erm"
)
func usageError(comment string) {
fmt.Println("ERROR:", comment)
const VERSION = "v0.9.5"
var Usage = func() {
fmt.Printf("\nSYNOPSIS\n")
fmt.Printf(" gocontentful -spaceid SpaceID -cmakey CMAKey [-contenttypes firsttype,secondtype...lasttype] path/to/target/package\n\n")
flag.Usage()
flag.PrintDefaults()
fmt.Printf("\nNote: The last segment of the path/to/target/package will be used as package name\n\n")
}
func usageError(comment string) {
fmt.Println("ERROR:", comment)
Usage()
os.Exit(1)
}
@ -26,14 +32,24 @@ func fatal(infos ...interface{}) {
}
func main() {
fmt.Printf("Contentful API Generator starting...\n\n")
// Get parameters from cmd line flags
flagSpaceID := flag.String("spaceid", "", "Contentful space ID")
flagCMAKey := flag.String("cmakey", "", "Contentful CMA key")
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")
flag.Parse()
if *flagVersion {
fmt.Println(VERSION)
os.Exit(0)
}
if *flagHelp {
Usage()
os.Exit(0)
}
if *flagSpaceID == "" || *flagCMAKey == "" {
usageError("Please specify the Contentful space ID and access Key")
}
@ -50,6 +66,8 @@ func main() {
usageError("Please specify the package name correctly (only small caps letters)")
}
fmt.Printf("Contentful API Generator starting...\n\n")
var flagContentTypesSlice []string
if *flagContentTypes != "" {
for _, contentType := range strings.Split(*flagContentTypes, ",") {