本文整理匯總了Golang中github.com/hypertornado/prago.App.AddCommand方法的典型用法代碼示例。如果您正苦於以下問題:Golang App.AddCommand方法的具體用法?Golang App.AddCommand怎麽用?Golang App.AddCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hypertornado/prago.App
的用法示例。
在下文中一共展示了App.AddCommand方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: bindAdminCommand
func (a *Admin) bindAdminCommand(app *prago.App) error {
adminCommand := app.CreateCommand("admin", "Admin tasks (migrate|drop|thumbnails)")
adminSubcommand := adminCommand.Arg("admincommand", "").Required().String()
app.AddCommand(adminCommand, func(app *prago.App) error {
switch *adminSubcommand {
case "migrate":
println("Migrating database")
err := a.Migrate(true)
if err == nil {
println("Migrate done")
}
return err
case "drop":
if utils.ConsoleQuestion("Really want to drop table?") {
println("Dropping table")
return a.UnsafeDropTables()
}
return nil
case "thumbnails":
println("Updating thumbnails")
return updateFiles(a)
default:
println("unknown admin subcommand " + *adminSubcommand)
}
return nil
})
return nil
}
示例2: Init
func (m MiddlewareDevelopment) Init(app *prago.App) error {
app.RecoveryFunc = DevelopmentRecovery
devCommand := app.CreateCommand("dev", "Development")
portFlag := devCommand.Flag("port", "server port").Short('p').Default("8585").Int()
developmentMode := devCommand.Flag("development", "Is in development mode").Default("t").Short('d').Bool()
app.AddCommand(devCommand, func(app *prago.App) error {
for _, v := range m.Settings.Less {
go developmentLess(v.SourceDir, v.Target)
}
for _, v := range m.Settings.TypeScript {
go developmentTypescript(v)
}
return app.ListenAndServe(*portFlag, *developmentMode)
})
return nil
}
示例3: Init
//Init Mysql middleware
func (m *Mysql) Init(app *prago.App) error {
dbUser := app.Config.GetString("dbUser")
dbPassword := app.Config.GetString("dbPassword")
dbName := app.Config.GetString("dbName")
db, err := ConnectMysql(dbUser, dbPassword, dbName)
if err != nil {
return err
}
app.Data()["db"] = db
dumpCommand := app.CreateCommand("dump", "Dump database")
app.AddCommand(dumpCommand, func(app *prago.App) error {
cmd := exec.Command("mysqldump", "-u"+dbUser, "-p"+dbPassword, dbName)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
panic(err)
}
return nil
})
return nil
}