mirror of
				https://github.com/beego/bee.git
				synced 2025-11-03 23:03:27 +00:00 
			
		
		
		
	add runmode flag on bee run to set BEEGO_RUNMODE env
This commit is contained in:
		
							
								
								
									
										15
									
								
								run.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								run.go
									
									
									
									
									
								
							@@ -24,7 +24,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var cmdRun = &Command{
 | 
					var cmdRun = &Command{
 | 
				
			||||||
	UsageLine: "run [appname] [watchall] [-main=*.go] [-downdoc=true]  [-gendoc=true] [-vendor=true] [-e=folderToExclude]  [-tags=goBuildTags]",
 | 
						UsageLine: "run [appname] [watchall] [-main=*.go] [-downdoc=true]  [-gendoc=true] [-vendor=true] [-e=folderToExclude]  [-tags=goBuildTags] [-runmode=BEEGO_RUNMODE]",
 | 
				
			||||||
	Short:     "run the app and start a Web server for development",
 | 
						Short:     "run the app and start a Web server for development",
 | 
				
			||||||
	Long: `
 | 
						Long: `
 | 
				
			||||||
Run command will supervise the file system of the beego project using inotify,
 | 
					Run command will supervise the file system of the beego project using inotify,
 | 
				
			||||||
@@ -51,6 +51,8 @@ var (
 | 
				
			|||||||
	vendorWatch bool
 | 
						vendorWatch bool
 | 
				
			||||||
	// Current user workspace
 | 
						// Current user workspace
 | 
				
			||||||
	currentGoPath string
 | 
						currentGoPath string
 | 
				
			||||||
 | 
						// Current runmode
 | 
				
			||||||
 | 
						runmode string
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
@@ -61,6 +63,7 @@ func init() {
 | 
				
			|||||||
	cmdRun.Flag.Var(&excludedPaths, "e", "Excluded paths[].")
 | 
						cmdRun.Flag.Var(&excludedPaths, "e", "Excluded paths[].")
 | 
				
			||||||
	cmdRun.Flag.BoolVar(&vendorWatch, "vendor", false, "Watch vendor folder")
 | 
						cmdRun.Flag.BoolVar(&vendorWatch, "vendor", false, "Watch vendor folder")
 | 
				
			||||||
	cmdRun.Flag.StringVar(&buildTags, "tags", "", "Build tags (https://golang.org/pkg/go/build/)")
 | 
						cmdRun.Flag.StringVar(&buildTags, "tags", "", "Build tags (https://golang.org/pkg/go/build/)")
 | 
				
			||||||
 | 
						cmdRun.Flag.StringVar(&runmode, "runmode", "", "Set BEEGO_RUNMODE env variable.")
 | 
				
			||||||
	exit = make(chan bool)
 | 
						exit = make(chan bool)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -100,6 +103,16 @@ func runApp(cmd *Command, args []string) int {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	Debugf("current path:%s\n", currpath)
 | 
						Debugf("current path:%s\n", currpath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if runmode == "prod" || runmode == "dev"{
 | 
				
			||||||
 | 
							os.Setenv("BEEGO_RUNMODE", runmode)
 | 
				
			||||||
 | 
							ColorLog("[INFO] Using '%s' as 'runmode'\n", os.Getenv("BEEGO_RUNMODE"))
 | 
				
			||||||
 | 
						}else if runmode != ""{
 | 
				
			||||||
 | 
							os.Setenv("BEEGO_RUNMODE", runmode)
 | 
				
			||||||
 | 
							ColorLog("[WARN] Using '%s' as 'runmode'\n", os.Getenv("BEEGO_RUNMODE"))
 | 
				
			||||||
 | 
						}else if os.Getenv("BEEGO_RUNMODE") != ""{
 | 
				
			||||||
 | 
							ColorLog("[WARN] Using '%s' as 'runmode'\n", os.Getenv("BEEGO_RUNMODE"))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := loadConfig()
 | 
						err := loadConfig()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err)
 | 
							ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user