cleanup reg command, make track dir2nick, calc abs path, unreg stub
This commit is contained in:
parent
f63736fe14
commit
a42b1f2dcc
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ warrend: cmd/warrend/warrend
|
||||||
cmd/warren/warren: cmd/warren/*.go
|
cmd/warren/warren: cmd/warren/*.go
|
||||||
cd cmd/warren && go build && ./warren build
|
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
|
cd cmd/warrend && ./../warren/warren build
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -11,16 +11,22 @@ import (
|
||||||
// "time"
|
// "time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var regUsage = `
|
|
||||||
warren reg - Register a deployment directory for running
|
|
||||||
`
|
|
||||||
var regCmd = &warren.Command{
|
var regCmd = &warren.Command{
|
||||||
Name: "reg",
|
Name: "reg",
|
||||||
Usage: regUsage,
|
|
||||||
Summary: "Register a deployment directory for running",
|
Summary: "Register a deployment directory for running",
|
||||||
Run: warrendRun,
|
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 = `
|
var statusUsage = `
|
||||||
warren status - Get the status from the warrend server
|
warren status - Get the status from the warrend server
|
||||||
`
|
`
|
||||||
|
@ -42,7 +48,7 @@ func warrendRun(cmd *warren.Command, args ...string) {
|
||||||
}
|
}
|
||||||
dir, _ := os.Getwd()
|
dir, _ := os.Getwd()
|
||||||
// pwd|arg1 arg2 arg3 ....
|
// 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)
|
resp, err := warren.ReadStringz(s)
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ func main() {
|
||||||
warren.RegisterCommand(deployCmd)
|
warren.RegisterCommand(deployCmd)
|
||||||
warren.RegisterCommand(statusCmd)
|
warren.RegisterCommand(statusCmd)
|
||||||
warren.RegisterCommand(regCmd)
|
warren.RegisterCommand(regCmd)
|
||||||
|
warren.RegisterCommand(unregCmd)
|
||||||
warren.RegisterCommand(versionCmd)
|
warren.RegisterCommand(versionCmd)
|
||||||
args := os.Args[1:]
|
args := os.Args[1:]
|
||||||
if len(args) == 0 || args[0] == "-h" {
|
if len(args) == 0 || args[0] == "-h" {
|
||||||
|
|
|
@ -8,9 +8,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var regUsage = `
|
var regUsage = `
|
||||||
status -
|
warren reg DEPLOYMENT_DIR [NICKNAME]
|
||||||
`
|
`
|
||||||
|
|
||||||
var regCmd = &SockCommand{
|
var regCmd = &SockCommand{
|
||||||
Command: warren.Command{
|
Command: warren.Command{
|
||||||
Name: "reg",
|
Name: "reg",
|
||||||
|
@ -20,6 +19,19 @@ var regCmd = &SockCommand{
|
||||||
Run: regRun,
|
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]
|
// reg path [nickname]
|
||||||
func regRun(cmd *SockCommand, c net.Conn, path string, args ...string) {
|
func regRun(cmd *SockCommand, c net.Conn, path string, args ...string) {
|
||||||
if (len(args) > 0 && args[0] == "help") || len(args) < 1 {
|
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
|
// get either supplied nick or parse from dir
|
||||||
d := new(conf.DeploymentMsg)
|
d := new(conf.DeploymentMsg)
|
||||||
d.Path = args[0]
|
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]) != "" {
|
if len(args) >= 2 && strings.TrimSpace(args[1]) != "" {
|
||||||
d.Name = args[1]
|
d.Name = args[1]
|
||||||
} else {
|
} 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)
|
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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func statusRun(cmd *SockCommand, c net.Conn, path string, args ...string) {
|
||||||
warren.WriteStringz(c, "Status\n")
|
warren.WriteStringz(c, "Status\n")
|
||||||
|
|
||||||
for n, p := range conf.GetConf().Deployments {
|
for n, p := range conf.GetConf().Deployments {
|
||||||
warren.WriteStringz(c, n+": "+p)
|
warren.WriteStringz(c, n+": "+p+"\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,10 @@ func loadConf() {
|
||||||
if conf.Deployments == nil {
|
if conf.Deployments == nil {
|
||||||
conf.Deployments = make(map[string]string)
|
conf.Deployments = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
// populate reverse map
|
||||||
|
for nick, dir := range conf.Deployments {
|
||||||
|
dirToNick[dir] = nick
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveConf() error {
|
func saveConf() error {
|
||||||
|
|
|
@ -11,6 +11,9 @@ type DeploymentMsg struct {
|
||||||
Reply chan error
|
Reply chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reverse look up map
|
||||||
|
var dirToNick map[string]string = make(map[string]string)
|
||||||
|
|
||||||
// Validate a deployment is ok to insert
|
// Validate a deployment is ok to insert
|
||||||
// internal thread unsafe
|
// internal thread unsafe
|
||||||
func validateDeployment(d *DeploymentMsg) error {
|
func validateDeployment(d *DeploymentMsg) error {
|
||||||
|
@ -19,6 +22,10 @@ func validateDeployment(d *DeploymentMsg) error {
|
||||||
return errors.New("Deployment with that name already exists")
|
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
|
// check if dir exists
|
||||||
if _, err := os.Stat(d.Path); err != nil {
|
if _, err := os.Stat(d.Path); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -34,6 +41,7 @@ func addDeployment(d *DeploymentMsg) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
conf.Deployments[d.Name] = d.Path
|
conf.Deployments[d.Name] = d.Path
|
||||||
|
dirToNick[d.Path] = d.Name
|
||||||
saveConf()
|
saveConf()
|
||||||
d.Reply <- nil
|
d.Reply <- nil
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -146,6 +146,8 @@ func main() {
|
||||||
Shutdown()
|
Shutdown()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
fmt.Println("warrend starting and listening...")
|
||||||
|
|
||||||
// Listen
|
// Listen
|
||||||
for {
|
for {
|
||||||
fd, err := cmdSock.Accept()
|
fd, err := cmdSock.Accept()
|
||||||
|
|
Loading…
Reference in New Issue