當前位置: 首頁>>代碼示例>>Golang>>正文


Golang App.CreateCommand方法代碼示例

本文整理匯總了Golang中github.com/hypertornado/prago.App.CreateCommand方法的典型用法代碼示例。如果您正苦於以下問題:Golang App.CreateCommand方法的具體用法?Golang App.CreateCommand怎麽用?Golang App.CreateCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/hypertornado/prago.App的用法示例。


在下文中一共展示了App.CreateCommand方法的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
}
開發者ID:hypertornado,項目名稱:prago,代碼行數:31,代碼來源:admin.go

示例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
}
開發者ID:hypertornado,項目名稱:prago,代碼行數:20,代碼來源:development.go

示例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
}
開發者ID:hypertornado,項目名稱:prago,代碼行數:25,代碼來源:mysql.go


注:本文中的github.com/hypertornado/prago.App.CreateCommand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。