warren/cmd/warrend/cmd_reg.go

84 lines
1.8 KiB
Go
Raw Normal View History

2015-02-14 19:42:02 +00:00
package main
import (
"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 = `
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,
}
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]
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 {
warren.WriteStringz(c, cmd.Usage)
2015-02-14 19:42:02 +00:00
return
}
// get either supplied nick or parse from dir
d := new(conf.DeploymentMsg)
2015-02-24 17:47:07 +00:00
d.Path = warren.AbsPath(path, args[0])
2015-02-14 19:42:02 +00:00
if len(args) >= 2 && strings.TrimSpace(args[1]) != "" {
d.Name = args[1]
} else {
parts := strings.Split(strings.Trim(d.Path, " /"), "/")
if parts[len(parts)-1] == "deploy" {
d.Name = parts[len(parts)-2]
} else {
d.Name = parts[len(parts)-1]
}
}
err := conf.AddDeployment(d)
2015-02-14 19:42:02 +00:00
if err != nil {
warren.WriteStringz(c, "ERROR: "+err.Error())
return
}
warren.WriteStringz(c, "Registered deployment "+d.Name+" at "+d.Path)
}
// 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-24 17:47:07 +00:00
err := conf.RmDeployment(args[0])
// Assume nick, check if registered
deps := conf.GetConf().Deployments
arg := args[0]
if _,ok := deps[arg]; !ok {
// not a registered nick, try as path
absPath := absPath(path, arg)
if _,ok := conf.
}
}