mirror of
https://github.com/casbin/bee.git
synced 2025-07-20 17:34:19 +08:00
Added PreRun phase to Command struct
Now each command has a PreRun function that will execute before calling the Run() function. This allows to show the banner and do some pre-check work. Also moved parsePackagesFromDir() to the main function to avoid getting called each time 'bee' is invoked.
This commit is contained in:
14
new.go
14
new.go
@ -52,24 +52,24 @@ the following files/directories structure:
|
||||
|
||||
func init() {
|
||||
cmdNew.Run = createApp
|
||||
cmdNew.PreRun = func(cmd *Command, args []string) { ShowShortVersionBanner() }
|
||||
}
|
||||
|
||||
func createApp(cmd *Command, args []string) int {
|
||||
ShowShortVersionBanner()
|
||||
w := NewColorWriter(os.Stdout)
|
||||
|
||||
if len(args) != 1 {
|
||||
logger.Error("Argument [appname] is missing")
|
||||
os.Exit(2)
|
||||
logger.Fatal("Argument [appname] is missing")
|
||||
}
|
||||
|
||||
apppath, packpath, err := checkEnv(args[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(2)
|
||||
logger.Fatalf("%s", err)
|
||||
}
|
||||
|
||||
if isExist(apppath) {
|
||||
logger.Errorf("Path (%s) already exists", apppath)
|
||||
logger.Warn("Do you want to overwrite it? [Yes|No] ")
|
||||
logger.Errorf(bold("Application '%s' already exists"), apppath)
|
||||
logger.Warn(bold("Do you want to overwrite it? [Yes|No] "))
|
||||
if !askForConfirmation() {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
Reference in New Issue
Block a user