Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &cobra.Command{ Use: "generate", Short: "generate gone loading code and import code", RunE: func(cmd *cobra.Command, args []string) (err error) { if len(scanDirs) == 0 { return errors.New("scan dir is empty") } cwd, _ := os.Getwd() fmt.Printf("current work dir: %s\n", cwd) for i := range scanDirs { absolutePath, err := filepath.Abs(scanDirs[i]) if err != nil { return err } scanDirs[i] = absolutePath } if mainPackageDir == "" { mainPackageDir, err = findFirstMainPackageDir(scanDirs) if err != nil { return err } } fmt.Printf("main package dir: %s\n", mainPackageDir) fmt.Printf("scan dirs: %v\n", scanDirs) moduleInfo, err := utils.FindModuleInfo(mainPackageDir) if err != nil { return err } var needImportPackages []string for _, dir := range scanDirs { packages, err := scanDirGenCode(dir, moduleInfo, mainPackageDir) if err != nil { return err } needImportPackages = append(needImportPackages, packages...) } if len(needImportPackages) > 0 { return genImportCode(mainPackageDir, needImportPackages) } err = os.Chdir(moduleInfo.ModulePath) if err != nil { return err } return utils.Command("go", []string{"mod", "tidy"}) }, }
Functions ¶
This section is empty.
Types ¶
type ModuleInfo ¶
Click to show internal directories.
Click to hide internal directories.