main.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. )
  7. var (
  8. err error
  9. _mode, _func string
  10. files []string
  11. parses []*parse
  12. )
  13. func main() {
  14. flag.StringVar(&_mode, "m", "test", "Generating code by Working mode. [test|interface|mock|upgrade...]")
  15. flag.StringVar(&_func, "func", "", "Generating code by function.")
  16. flag.Parse()
  17. if len(os.Args) == 1 {
  18. println("Creater is a tool for generating code.\n\nUsage: creater [-m]")
  19. flag.PrintDefaults()
  20. return
  21. }
  22. if err = parseArgs(os.Args[1:], &files, 0); err != nil {
  23. panic(err)
  24. }
  25. switch _mode {
  26. case "monkey":
  27. if parses, err = parseFile(files...); err != nil {
  28. panic(err)
  29. }
  30. if err = genMonkey(parses); err != nil {
  31. panic(err)
  32. }
  33. case "test":
  34. if parses, err = parseFile(files...); err != nil {
  35. panic(err)
  36. }
  37. if err = genTest(parses); err != nil {
  38. panic(err)
  39. }
  40. case "interface":
  41. if parses, err = parseFile(files...); err != nil {
  42. panic(err)
  43. }
  44. if err = genInterface(parses); err != nil {
  45. panic(err)
  46. }
  47. case "mock":
  48. if err = genMock(files...); err != nil {
  49. panic(err)
  50. }
  51. case "upgrade":
  52. if err = upBladeMaster(files); err != nil {
  53. panic(err)
  54. }
  55. default:
  56. }
  57. fmt.Println(moha)
  58. }