v1.3.4.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package migrationnotes
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "strings"
  6. "github.com/urfave/cli"
  7. )
  8. func migrateBefore1_3_4(ctx *cli.Context) error {
  9. dir := ctx.String("dir")
  10. style := ctx.String("style")
  11. ok, err := needShow1_3_4(dir, style)
  12. if err != nil {
  13. return err
  14. }
  15. if !ok {
  16. return nil
  17. }
  18. fmt.Println(`It seems like that your goctl has just been upgraded to version 1.3.4 or later, which refactored the code of the model module. The original XXXmodel.go has been split into XXXmodel_gen.go (read-only) and XXXmodel.go. You just need to follow these steps to complete the migration:
  19. 1. back up the original XXXmodel.go (make sure the file name is no longer in the current directory)
  20. 2. re-run the generate command (a new XXXmodel.go will be created)
  21. 3. populate XXXmodel.go with the code that is not generated by goctl according to the comments in XXXmodel_gen.go`)
  22. return nil
  23. }
  24. func needShow1_3_4(dir, style string) (bool, error) {
  25. files, err := ioutil.ReadDir(dir)
  26. if err != nil {
  27. return false, nil
  28. }
  29. // Returns false when the directory contains a file with the suffix "_gen.go"
  30. // In addition, it returns true if it contains a model file extension.
  31. // In other case, false is returned.
  32. for _, f := range files {
  33. if f.IsDir() {
  34. continue
  35. }
  36. if strings.HasSuffix(f.Name(), "_gen.go") {
  37. return false, nil
  38. }
  39. }
  40. modelSuffix, err := getModelSuffix(style)
  41. if err != nil {
  42. return false, err
  43. }
  44. for _, f := range files {
  45. if !f.IsDir() && strings.HasSuffix(f.Name(), modelSuffix) {
  46. return true, nil
  47. }
  48. }
  49. return false, nil
  50. }