2015-02-14 19:42:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-02-15 21:19:08 +00:00
|
|
|
"github.com/dballard/warren/cmd/warrend/conf"
|
2015-02-14 19:42:02 +00:00
|
|
|
"github.com/dballard/warren/lib/warren"
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var regUsage = `
|
2015-02-22 02:43:52 +00:00
|
|
|
warren reg DEPLOYMENT_DIR [NICKNAME]
|
2015-02-14 19:42:02 +00:00
|
|
|
`
|
|
|
|
var regCmd = &SockCommand{
|
|
|
|
Command: warren.Command{
|
|
|
|
Name: "reg",
|
|
|
|
Usage: regUsage,
|
|
|
|
Summary: "Register a deployment directory for running",
|
|
|
|
},
|
|
|
|
Run: regRun,
|
|
|
|
}
|
|
|
|
|
2015-02-22 02:43:52 +00:00
|
|
|
var unregUsage = `
|
|
|
|
warren unreg DEPLOYMENT_DIR
|
|
|
|
warren unreg NICKNAME
|
|
|
|
`
|
|
|
|
var unregCmd = &SockCommand{
|
|
|
|
Command: warren.Command{
|
|
|
|
Name: "unreg",
|
|
|
|
Usage: unregUsage,
|
|
|
|
Summary: "Unregister a deployment directory and stop it running",
|
|
|
|
},
|
|
|
|
Run: unregRun,
|
|
|
|
}
|
|
|
|
|
2015-02-14 19:42:02 +00:00
|
|
|
// reg path [nickname]
|
2015-02-19 05:58:29 +00:00
|
|
|
func regRun(cmd *SockCommand, c net.Conn, path string, args ...string) {
|
2015-02-14 19:42:02 +00:00
|
|
|
if (len(args) > 0 && args[0] == "help") || len(args) < 1 {
|
2015-02-22 01:29:46 +00:00
|
|
|
warren.WriteStringz(c, cmd.Usage)
|
2015-02-14 19:42:02 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// get either supplied nick or parse from dir
|
2015-04-03 06:52:03 +00:00
|
|
|
d := conf.NewMsg(conf.AddDeployment)
|
|
|
|
|
|
|
|
d.Args["path"] = warren.AbsPath(path, args[0])
|
|
|
|
|
2015-02-22 02:43:52 +00:00
|
|
|
|
2015-02-14 19:42:02 +00:00
|
|
|
if len(args) >= 2 && strings.TrimSpace(args[1]) != "" {
|
2015-04-03 06:52:03 +00:00
|
|
|
d.Args["name"] = args[1]
|
2015-02-14 19:42:02 +00:00
|
|
|
} else {
|
2015-04-03 06:52:03 +00:00
|
|
|
parts := strings.Split(strings.Trim(d.Args["path"], " /"), "/")
|
2015-02-14 19:42:02 +00:00
|
|
|
if parts[len(parts)-1] == "deploy" {
|
2015-04-03 06:52:03 +00:00
|
|
|
d.Args["name"] = parts[len(parts)-2]
|
2015-02-14 19:42:02 +00:00
|
|
|
} else {
|
2015-04-03 06:52:03 +00:00
|
|
|
d.Args["name"] = parts[len(parts)-1]
|
2015-02-14 19:42:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 06:52:03 +00:00
|
|
|
|
|
|
|
err := d.Call()
|
2015-02-14 19:42:02 +00:00
|
|
|
if err != nil {
|
|
|
|
warren.WriteStringz(c, "ERROR: "+err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-04-03 06:52:03 +00:00
|
|
|
warren.WriteStringz(c, "Registered deployment "+d.Args["name"]+ " at "+d.Args["path"])
|
2015-02-14 19:42:02 +00:00
|
|
|
}
|
2015-02-22 02:43:52 +00:00
|
|
|
|
|
|
|
// unreg path
|
|
|
|
// unreg nick
|
|
|
|
func unregRun(cmd *SockCommand, c net.Conn, path string, args ...string) {
|
2015-02-24 17:47:07 +00:00
|
|
|
if (len(args) > 0 && args[0] == "help") || len(args) < 1 {
|
|
|
|
warren.WriteStringz(c, cmd.Usage)
|
|
|
|
return
|
|
|
|
}
|
2015-02-22 02:43:52 +00:00
|
|
|
|
2015-04-04 00:24:57 +00:00
|
|
|
d := conf.NewMsg(conf.RmDeploymen)
|
|
|
|
d.Args["arg"] = args[0]
|
|
|
|
d.Args["path"] = path
|
|
|
|
err := d.Call()
|
2015-03-29 17:45:43 +00:00
|
|
|
if err != nil {
|
|
|
|
warren.WriteStringz(c, "ERROR: " + err.Error())
|
|
|
|
return
|
2015-04-04 00:24:57 +00:00
|
|
|
}
|
2015-03-29 17:45:43 +00:00
|
|
|
warren.WriteStringz(c, "Unregistered deployment " + args[0])
|
2015-02-22 02:43:52 +00:00
|
|
|
}
|
2015-03-29 17:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|