48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package main
|
|
|
|
import "github.com/spf13/cobra"
|
|
|
|
func deployCmd() *cobra.Command {
|
|
var outter Outter
|
|
cmd := &cobra.Command{
|
|
Use: "deploy",
|
|
Aliases: []string{"d"},
|
|
Short: "deploy project to upyun",
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
outter.Config = readConfigFile()
|
|
config := outter.Config.Deploy
|
|
switch config.Type {
|
|
case UpyunDeploy:
|
|
if !isCommandExist("upx") {
|
|
if err := goInstall("github.com/upyun/upx"); err != nil {
|
|
sfault("install upx failed: %+v", err)
|
|
}
|
|
}
|
|
case GitDeploy:
|
|
}
|
|
|
|
// generate source
|
|
if err := generateCmd().Execute(); err != nil {
|
|
sfault("generate project failed: %v", err)
|
|
}
|
|
},
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
config := outter.Config.Deploy
|
|
switch config.Type {
|
|
case UpyunDeploy:
|
|
if config.UpyunAuth == "" {
|
|
serr("please config upyun auth string: upx auth [bucket] [operator] [password]")
|
|
return
|
|
}
|
|
if err := uploadToUpyun(config.UpyunAuth); err != nil {
|
|
serr("%v", err)
|
|
return
|
|
}
|
|
sout("deploy to upyun success")
|
|
}
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|