feat: rename remote name
This commit is contained in:
parent
450dfc9052
commit
4b9c1fc3dd
40
cmd/remote/rename.go
Normal file
40
cmd/remote/rename.go
Normal 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)
|
||||
}
|
@ -360,7 +360,19 @@ func (fc *FluckyConfig) RenameSensor(oldName, newName string) error {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user