feat: rename remote name

This commit is contained in:
Markus Pesch 2019-02-28 20:13:11 +01:00
parent 450dfc9052
commit 4b9c1fc3dd
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 53 additions and 1 deletions

40
cmd/remote/rename.go Normal file
View File

@ -0,0 +1,40 @@
package remote
import (
"log"
"git.cryptic.systems/fh-trier/go-flucky/pkg/config"
"github.com/spf13/cobra"
)
var renameRemoteCmd = &cobra.Command{
Use: "rename",
Short: "Rename Remote Server",
Args: cobra.ExactArgs(2),
Example: "flucky remote rename origin slave",
Run: func(cmd *cobra.Command, args []string) {
// read configuration
fc, err := config.Read(cfg)
if err != nil {
log.Fatalln(err)
}
// rename remote address
err = fc.RenameRemote(args[0], args[1])
if err != nil {
log.Fatalln(err)
}
// save new configuration
err = config.Write(fc, cfg)
if err != nil {
log.Fatalln(err)
}
},
}
func init() {
remoteCmd.AddCommand(renameRemoteCmd)
}

View File

@ -360,7 +360,19 @@ func (fc *FluckyConfig) RenameSensor(oldName, newName string) error {
return nil return nil
} }
} }
return fmt.Errorf("Could not find sensor %v and replace the name", oldName) return fmt.Errorf("Could not find sensor %v to replace into ", oldName)
}
// RenameRemote renames a remote address identified by the name or the UUID
func (fc *FluckyConfig) RenameRemote(oldName, newName string) error {
for _, remote := range fc.Remotes {
if remote.Name == oldName ||
remote.RemoteID == oldName {
remote.Name = newName
return nil
}
}
return fmt.Errorf("Could not find remote name %v to replace into %v", oldName, newName)
} }
// ToJSON returns the struct as JSON string // ToJSON returns the struct as JSON string