diff --git a/cmd/warrend/cmd_reg.go b/cmd/warrend/cmd_reg.go index 3bc06b4..e5d2b37 100644 --- a/cmd/warrend/cmd_reg.go +++ b/cmd/warrend/cmd_reg.go @@ -40,26 +40,29 @@ 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 = warren.AbsPath(path, args[0]) + d := conf.NewMsg(conf.AddDeployment) + + d.Args["path"] = warren.AbsPath(path, args[0]) + if len(args) >= 2 && strings.TrimSpace(args[1]) != "" { - d.Name = args[1] + d.Args["name"] = args[1] } else { - parts := strings.Split(strings.Trim(d.Path, " /"), "/") + parts := strings.Split(strings.Trim(d.Args["path"], " /"), "/") if parts[len(parts)-1] == "deploy" { - d.Name = parts[len(parts)-2] + d.Args["name"] = parts[len(parts)-2] } else { - d.Name = parts[len(parts)-1] + d.Args["name"] = parts[len(parts)-1] } } - err := conf.AddDeployment(d) + + err := d.Call() if err != nil { warren.WriteStringz(c, "ERROR: "+err.Error()) return } - warren.WriteStringz(c, "Registered deployment "+d.Name+" at "+d.Path) + warren.WriteStringz(c, "Registered deployment "+d.Args["name"]+ " at "+d.Args["path"]) } // unreg path @@ -70,11 +73,11 @@ func unregRun(cmd *SockCommand, c net.Conn, path string, args ...string) { return } - err := conf.RmDeployment(args[0]) + /*err := conf.RmDeployment(args[0]) if err != nil { warren.WriteStringz(c, "ERROR: " + err.Error()) return - } + }*/ warren.WriteStringz(c, "Unregistered deployment " + args[0]) } diff --git a/cmd/warrend/conf/conf.go b/cmd/warrend/conf/conf.go index b5e37af..0774dae 100644 --- a/cmd/warrend/conf/conf.go +++ b/cmd/warrend/conf/conf.go @@ -17,11 +17,11 @@ const ( type Msg struct { mType MsgType reply chan error - args map[string]string + Args map[string]string } -func NewMsg(mType MsgType, args map[string]string) *Msg { - var m = &Msg{mType, make(chan error), args} +func NewMsg(mType MsgType) *Msg { + var m = &Msg{mType, make(chan error), make(map[string]string)} return m } @@ -87,7 +87,7 @@ func saveConf() error { return errors.New("Error: Could not write to file: " + err.Error()) } - return ni l + return nil } func GetConf() Conf { @@ -108,9 +108,9 @@ func Run() { for { m := <- confChan - select (m.mType) { - case dm := <-addDeploymentChan: - addDeployment(&dm) + switch (m.mType) { + case AddDeployment: + addDeployment(&m) } } diff --git a/cmd/warrend/conf/deployments.go b/cmd/warrend/conf/deployments.go index 21ca291..f52583f 100644 --- a/cmd/warrend/conf/deployments.go +++ b/cmd/warrend/conf/deployments.go @@ -5,62 +5,25 @@ import ( "os" ) -type DeploymentMsg struct { - Name string - Path string - 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 { - // check if exists - if _, ok := conf.Deployments[d.Name]; ok { - 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 - } - return nil -} // given a valid deployment, add it // internal, thread unsafe -func addDeployment(d *DeploymentMsg) error { +func addDeployment(d *Msg) error { if err := validateDeployment(d); err != nil { - d.Reply <- err + d.reply <- err return err } - conf.Deployments[d.Name] = d.Path - dirToNick[d.Path] = d.Name + conf.Deployments[d.Args["name"]] = d.Args["path"] + dirToNick[d.Args["path"]] = d.Args["name"] saveConf() - d.Reply <- nil + d.reply <- nil return nil } - -// conf API interface to add a deployment, vets it -func AddDeployment(d *DeploymentMsg) error { - - d.Reply = make(chan error) - // add to conf / save - addDeploymentChan <- *d - err := <-d.Reply - return err - - // TODO: register with runner, like conf would - - return nil -} - +/* func RmDeployment(string arg) error { reply = make(chan error) rmDeploymentChan <- @@ -74,3 +37,22 @@ func RmDeployment(string arg) error { // if _,ok := conf. } } +*/ +// Validate a deployment is ok to insert +// internal thread unsafe +func validateDeployment(d *Msg) error { + // check if exists + if _, ok := conf.Deployments[d.Args["Name"]]; ok { + return errors.New("Deployment with that name already exists") + } + + if r, ok := dirToNick[d.Args["path"]]; ok { + return errors.New("Directory with that name already registered under nick '" + r + "'") + } + + // check if dir exists + if _, err := os.Stat(d.Args["path"]); err != nil { + return err + } + return nil +} \ No newline at end of file