Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RootCMD = &cobra.Command{ Use: "snips", Short: "A code generator for RESTful APIs.", Long: `A code generator for RESTful APIs. For example: $ snips -f ./specs/qingstor/api.json -t ./templates/qingstor/go \ -o ./publish/qingstor-sdk-go/service $ ... $ snips --file=./specs/qingstor/api.json \ --template=./templates/qingstor/ruby \ --output=./publish/qingstor-sdk-ruby/lib/qingstor/sdk/service $ ... Copyright (C) 2016-2017 Yunify, Inc.`, PreRunE: func(cmd *cobra.Command, args []string) error { if flagVersion { return nil } if codeSpecFile == "" { return errors.New("please specify the spec file") } if _, err := os.Stat(codeSpecFile); err != nil { return errors.New("please make sure the spec file exists") } if codeTemplateDirectory == "" { return errors.New("please specify templates directory") } if _, err := os.Stat(codeTemplateDirectory); err != nil { return errors.New("please make sure the templates directory exists") } if codeOutputDirectory == "" { return errors.New("please specify output files directory") } return nil }, Run: func(cmd *cobra.Command, args []string) { if flagVersion { fmt.Println("snips version " + constants.Version) return } loadedTemplates, _, err := templates.LoadTemplates(codeTemplateDirectory) utils.CheckErrorForExit(err) fmt.Println("Loaded templates from " + codeTemplateDirectory) fmt.Println(len(loadedTemplates), "template(s) detected.") spec, err := specs.LoadSpec(codeSpecFile, codeSpecFormat) utils.CheckErrorForExit(err) fmt.Printf("Loaded specification file %s (%s)\n\n", codeSpecFile, codeSpecFormat) if spec != nil { codeCapsule := &capsules.BaseCapsule{CapsulePowder: &capsules.CapsulePowder{}} codeGenerator := generator.New() codeCapsule.SetData(spec.Data) sharedTemplateContent := "" if template := loadedTemplates["shared"]; template != nil { sharedTemplateContent = template.FileContent } if template := loadedTemplates["service"]; template != nil { template.FileContent += sharedTemplateContent template.UpdateOutputFilename(spec.Data.Service.Name, template.OutputFileNaming.Style) template.UpdateOutputFilePath(codeOutputDirectory) codeCapsule.SetMode("", "") codeGenerator.Set(codeCapsule, template) err = codeGenerator.Run() utils.CheckErrorForExit(err) } if template := loadedTemplates["sub_service"]; template != nil { template.FileContent += sharedTemplateContent for _, subService := range spec.Data.SubServices { template.UpdateOutputFilename(subService.Name, template.OutputFileNaming.Style) template.UpdateOutputFilePath(codeOutputDirectory) codeCapsule.SetMode(template.ID, subService.ID) codeGenerator.Set(codeCapsule, template) err = codeGenerator.Run() utils.CheckErrorForExit(err) } } if template := loadedTemplates["types"]; template != nil { template.FileContent += sharedTemplateContent template.UpdateOutputFilename("types", template.OutputFileNaming.Style) template.UpdateOutputFilePath(codeOutputDirectory) codeCapsule.SetMode("", "") codeGenerator.Set(codeCapsule, template) err = codeGenerator.Run() utils.CheckErrorForExit(err) } } fmt.Println("\nEverything looks fine.") }, }
RootCMD represents the base command when called without any subcommands.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.