beego bee tool mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.8KB

  1. // Copyright 2013 bee authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"): you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. // License for the specific language governing permissions and limitations
  13. // under the License.
  14. package main
  15. import (
  16. "flag"
  17. "log"
  18. "os"
  19. "github.com/beego/bee/cmd"
  20. "github.com/beego/bee/cmd/commands"
  21. "github.com/beego/bee/config"
  22. "github.com/beego/bee/generate/swaggergen"
  23. "github.com/beego/bee/utils"
  24. )
  25. var (
  26. workspace = os.Getenv("BeeWorkspace")
  27. )
  28. func main() {
  29. currentpath, _ := os.Getwd()
  30. if workspace != "" {
  31. currentpath = workspace
  32. }
  33. flag.Usage = cmd.Usage
  34. flag.Parse()
  35. log.SetFlags(0)
  36. args := flag.Args()
  37. if len(args) < 1 {
  38. cmd.Usage()
  39. os.Exit(2)
  40. return
  41. }
  42. if args[0] == "help" {
  43. cmd.Help(args[1:])
  44. return
  45. }
  46. for _, c := range commands.AvailableCommands {
  47. if c.Name() == args[0] && c.Run != nil {
  48. c.Flag.Usage = func() { c.Usage() }
  49. if c.CustomFlags {
  50. args = args[1:]
  51. } else {
  52. c.Flag.Parse(args[1:])
  53. args = c.Flag.Args()
  54. }
  55. if c.PreRun != nil {
  56. c.PreRun(c, args)
  57. }
  58. config.LoadConfig()
  59. // Check if current directory is inside the GOPATH,
  60. // if so parse the packages inside it.
  61. if utils.IsInGOPATH(currentpath) && cmd.IfGenerateDocs(c.Name(), args) {
  62. swaggergen.ParsePackagesFromDir(currentpath)
  63. }
  64. os.Exit(c.Run(c, args))
  65. return
  66. }
  67. }
  68. utils.PrintErrorAndExit("Unknown subcommand", cmd.ErrorTemplate)
  69. }