package main import ( "github.com/dballard/warren/cmd/warrend/conf" "github.com/dballard/warren/lib/warren" "bufio" "strings" ) var regUsage = ` warren reg DEPLOYMENT_DIR [NICKNAME] ` 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, } // reg path [nickname] func regRun(cmd *SockCommand, writer *bufio.Writer, path string, args ...string) { if len(args) == 0 || args[0] == "" || (len(args) > 0 && args[0] == "help") { writer.WriteString(cmd.Usage) return } // get either supplied nick or parse from dir d := conf.NewMsg(conf.AddDeployment) d.Args["path"] = warren.AbsPath(path, args[0]) if len(args) >= 2 && strings.TrimSpace(args[1]) != "" { d.Args["name"] = args[1] } else { parts := strings.Split(strings.Trim(d.Args["path"], " /"), "/") if parts[len(parts)-1] == "deploy" { d.Args["name"] = parts[len(parts)-2] } else { d.Args["name"] = parts[len(parts)-1] } } err := d.Call() if err != nil { writer.WriteString("ERROR: "+err.Error()) return } writer.WriteString("Registered deployment "+d.Args["name"]+ " at "+d.Args["path"]) } // unreg path // unreg nick func unregRun(cmd *SockCommand, writer *bufio.Writer, path string, args ...string) { if (len(args) > 0 && args[0] == "help") || len(args) < 1 { writer.WriteString(cmd.Usage) return } d := conf.NewMsg(conf.RmDeploymen) d.Args["arg"] = args[0] d.Args["path"] = path err := d.Call() if err != nil { writer.WriteString("ERROR: " + err.Error()) return } writer.WriteString("Unregistered deployment " + args[0]) }