in extra/aws-sdk-go/private/model/cli/gen-api/main.go [49:152]
func main() {
var svcPath, svcImportPath string
flag.StringVar(&svcPath, "path", "service",
"The `path` to generate service clients in to.",
)
flag.StringVar(&svcImportPath, "svc-import-path",
api.SDKImportRoot+"/service",
"The Go `import path` to generate client to be under.",
)
var ignoreUnsupportedAPIs bool
flag.BoolVar(&ignoreUnsupportedAPIs, "ignore-unsupported-apis",
true,
"Ignores API models that use unsupported features",
)
var strictServiceId bool
flag.BoolVar(&strictServiceId, "use-service-id", false, "enforce strict usage of the serviceId from the model")
flag.Usage = usage
flag.Parse()
if len(os.Getenv("AWS_SDK_CODEGEN_DEBUG")) != 0 {
api.LogDebug(os.Stdout)
}
// Make sure all paths are based on platform's pathing not Unix
globs := flag.Args()
for i, g := range globs {
globs[i] = filepath.FromSlash(g)
}
svcPath = filepath.FromSlash(svcPath)
modelPaths, err := api.ExpandModelGlobPath(globs...)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to glob file pattern", err)
os.Exit(1)
}
modelPaths, _ = api.TrimModelServiceVersions(modelPaths)
loader := api.Loader{
BaseImport: svcImportPath,
IgnoreUnsupportedAPIs: ignoreUnsupportedAPIs,
StrictServiceId: strictServiceId,
}
apis, err := loader.Load(modelPaths)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to load API models", err)
os.Exit(1)
}
if len(apis) == 0 {
fmt.Fprintf(os.Stderr, "expected to load models, but found none")
os.Exit(1)
}
if v := os.Getenv("SERVICES"); len(v) != 0 {
svcs := strings.Split(v, ",")
for pkgName, a := range apis {
var found bool
for _, include := range svcs {
if a.PackageName() == include {
found = true
break
}
}
if !found {
delete(apis, pkgName)
}
}
}
var wg sync.WaitGroup
servicePaths := map[string]struct{}{}
for _, a := range apis {
if _, ok := excludeServices[a.PackageName()]; ok {
continue
}
// Create the output path for the model.
pkgDir := filepath.Join(svcPath, a.PackageName())
os.MkdirAll(filepath.Join(pkgDir, a.InterfacePackageName()), 0775)
if _, ok := servicePaths[pkgDir]; ok {
fmt.Fprintf(os.Stderr,
"attempted to generate a client into %s twice. Second model package, %v\n",
pkgDir, a.PackageName())
os.Exit(1)
}
servicePaths[pkgDir] = struct{}{}
g := &generateInfo{
API: a,
PackageDir: pkgDir,
}
wg.Add(1)
go func() {
defer wg.Done()
writeServiceFiles(g, pkgDir)
}()
}
wg.Wait()
}