2017-03-06 23:58:53 +00:00
package generate
import (
"strings"
2020-12-16 05:20:41 +00:00
"github.com/beego/bee/v2/cmd/commands/migrate"
beeLogger "github.com/beego/bee/v2/logger"
"github.com/beego/bee/v2/utils"
2017-03-06 23:58:53 +00:00
)
func GenerateScaffold ( sname , fields , currpath , driver , conn string ) {
beeLogger . Log . Infof ( "Do you want to create a '%s' model? [Yes|No] " , sname )
// Generate the model
if utils . AskForConfirmation ( ) {
GenerateModel ( sname , fields , currpath )
}
// Generate the controller
beeLogger . Log . Infof ( "Do you want to create a '%s' controller? [Yes|No] " , sname )
if utils . AskForConfirmation ( ) {
GenerateController ( sname , currpath )
}
// Generate the views
beeLogger . Log . Infof ( "Do you want to create views for this '%s' resource? [Yes|No] " , sname )
if utils . AskForConfirmation ( ) {
GenerateView ( sname , currpath )
}
// Generate a migration
beeLogger . Log . Infof ( "Do you want to create a '%s' migration and schema for this resource? [Yes|No] " , sname )
if utils . AskForConfirmation ( ) {
upsql := ""
downsql := ""
if fields != "" {
dbMigrator := NewDBDriver ( )
upsql = dbMigrator . GenerateCreateUp ( sname )
downsql = dbMigrator . GenerateCreateDown ( sname )
}
GenerateMigration ( sname , upsql , downsql , currpath )
}
// Run the migration
beeLogger . Log . Infof ( "Do you want to migrate the database? [Yes|No] " )
if utils . AskForConfirmation ( ) {
2018-11-12 12:09:26 +00:00
migrate . MigrateUpdate ( currpath , driver , conn , "" )
2017-03-06 23:58:53 +00:00
}
beeLogger . Log . Successf ( "All done! Don't forget to add beego.Router(\"/%s\" ,&controllers.%sController{}) to routers/route.go\n" , sname , strings . Title ( sname ) )
}