diff --git a/Makefile b/Makefile index c67127a..0b389fd 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ warrend: cmd/warrend/warrend cmd/warren/warren: cmd/warren/*.go cd cmd/warren && go build && ./warren build -cmd/warrend/warrend: cmd/warren/warren cmd/warrend/*.go +cmd/warrend/warrend: cmd/warren/warren cmd/warrend/*.go cmd/warrend/conf/*.go cd cmd/warrend && ./../warren/warren build clean: diff --git a/cmd/warren/cmd_warrend.go b/cmd/warren/cmd_warrend.go index 1627049..83f4b7e 100644 --- a/cmd/warren/cmd_warrend.go +++ b/cmd/warren/cmd_warrend.go @@ -11,16 +11,22 @@ import ( // "time" ) -var regUsage = ` -warren reg - Register a deployment directory for running -` var regCmd = &warren.Command{ Name: "reg", - Usage: regUsage, Summary: "Register a deployment directory for running", Run: warrendRun, } +var unregUsage = ` +warren unreg DEPLOYMENT_DIR +warren unreg NICKNAME +` +var unregCmd = &warren.Command{ + Name: "unreg", + Summary: "Unregister a deployment directory and stop it running", + Run: warrendRun, +} + var statusUsage = ` warren status - Get the status from the warrend server ` @@ -42,7 +48,7 @@ func warrendRun(cmd *warren.Command, args ...string) { } dir, _ := os.Getwd() // pwd|arg1 arg2 arg3 .... - warren.WriteStringz(s, dir+"|"+cmd.Name+"|"+strings.Join(args, "|")) + warren.WriteStringz(s, dir+"/|"+cmd.Name+"|"+strings.Join(args, "|")) resp, err := warren.ReadStringz(s) diff --git a/cmd/warren/main.go b/cmd/warren/main.go index e9123d9..afb5a20 100644 --- a/cmd/warren/main.go +++ b/cmd/warren/main.go @@ -27,6 +27,7 @@ func main() { warren.RegisterCommand(deployCmd) warren.RegisterCommand(statusCmd) warren.RegisterCommand(regCmd) + warren.RegisterCommand(unregCmd) warren.RegisterCommand(versionCmd) args := os.Args[1:] if len(args) == 0 || args[0] == "-h" { diff --git a/cmd/warrend/cmd_reg.go b/cmd/warrend/cmd_reg.go index e98d1fe..2b9d398 100644 --- a/cmd/warrend/cmd_reg.go +++ b/cmd/warrend/cmd_reg.go @@ -8,9 +8,8 @@ import ( ) var regUsage = ` -status - +warren reg DEPLOYMENT_DIR [NICKNAME] ` - var regCmd = &SockCommand{ Command: warren.Command{ Name: "reg", @@ -20,6 +19,19 @@ var regCmd = &SockCommand{ 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, c net.Conn, path string, args ...string) { if (len(args) > 0 && args[0] == "help") || len(args) < 1 { @@ -30,6 +42,16 @@ func regRun(cmd *SockCommand, c net.Conn, path string, args ...string) { // get either supplied nick or parse from dir d := new(conf.DeploymentMsg) d.Path = args[0] + + // ./local_path + if d.Path[0] == '.' { + d.Path = path + d.Path[2:] + } else + // local_path + if d.Path[0] != '/' { + d.Path = path + d.Path + } + if len(args) >= 2 && strings.TrimSpace(args[1]) != "" { d.Name = args[1] } else { @@ -48,3 +70,9 @@ func regRun(cmd *SockCommand, c net.Conn, path string, args ...string) { 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) { + +} diff --git a/cmd/warrend/cmd_status.go b/cmd/warrend/cmd_status.go index e045a55..8fa1eb4 100644 --- a/cmd/warrend/cmd_status.go +++ b/cmd/warrend/cmd_status.go @@ -28,7 +28,7 @@ func statusRun(cmd *SockCommand, c net.Conn, path string, args ...string) { warren.WriteStringz(c, "Status\n") for n, p := range conf.GetConf().Deployments { - warren.WriteStringz(c, n+": "+p) + warren.WriteStringz(c, n+": "+p+"\n") } } diff --git a/cmd/warrend/conf/conf.go b/cmd/warrend/conf/conf.go index bd99788..4175be7 100644 --- a/cmd/warrend/conf/conf.go +++ b/cmd/warrend/conf/conf.go @@ -41,6 +41,10 @@ func loadConf() { if conf.Deployments == nil { conf.Deployments = make(map[string]string) } + // populate reverse map + for nick, dir := range conf.Deployments { + dirToNick[dir] = nick + } } func saveConf() error { diff --git a/cmd/warrend/conf/deployments.go b/cmd/warrend/conf/deployments.go index 7c8f138..223f4d0 100644 --- a/cmd/warrend/conf/deployments.go +++ b/cmd/warrend/conf/deployments.go @@ -11,6 +11,9 @@ type DeploymentMsg struct { Reply chan error } +// reverse look up map +var dirToNick map[string]string = make(map[string]string) + // Validate a deployment is ok to insert // internal thread unsafe func validateDeployment(d *DeploymentMsg) error { @@ -19,6 +22,10 @@ func validateDeployment(d *DeploymentMsg) error { return errors.New("Deployment with that name already exists") } + if r, ok := dirToNick[d.Path]; ok { + return errors.New("Directory with that name already registered under nick '" + r + "'") + } + // check if dir exists if _, err := os.Stat(d.Path); err != nil { return err @@ -34,6 +41,7 @@ func addDeployment(d *DeploymentMsg) error { return err } conf.Deployments[d.Name] = d.Path + dirToNick[d.Path] = d.Name saveConf() d.Reply <- nil return nil diff --git a/cmd/warrend/main.go b/cmd/warrend/main.go index 5149245..80d02d8 100644 --- a/cmd/warrend/main.go +++ b/cmd/warrend/main.go @@ -146,6 +146,8 @@ func main() { Shutdown() }() + fmt.Println("warrend starting and listening...") + // Listen for { fd, err := cmdSock.Accept()