51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/dballard/warren/lib/warren"
|
||
|
"net"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
var regUsage = `
|
||
|
status -
|
||
|
`
|
||
|
|
||
|
var regCmd = &SockCommand{
|
||
|
Command: warren.Command{
|
||
|
Name: "reg",
|
||
|
Usage: regUsage,
|
||
|
Summary: "Register a deployment directory for running",
|
||
|
Help: regUsage,
|
||
|
},
|
||
|
Run: regRun,
|
||
|
}
|
||
|
|
||
|
// reg path [nickname]
|
||
|
func regRun(cmd *SockCommand, c net.Conn, args ...string) {
|
||
|
if (len(args) > 0 && args[0] == "help") || len(args) < 1 {
|
||
|
warren.WriteStringz(c, cmd.Help)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// get either supplied nick or parse from dir
|
||
|
d := new(Deployment)
|
||
|
d.Path = args[0]
|
||
|
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 := addDeployment(d)
|
||
|
if err != nil {
|
||
|
warren.WriteStringz(c, "ERROR: "+err.Error())
|
||
|
return
|
||
|
}
|
||
|
|
||
|
warren.WriteStringz(c, "Registered deployment "+d.Name+" at "+d.Path)
|
||
|
}
|