2018-11-19 21:36:21 +00:00
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2019-02-17 17:23:59 +00:00
|
|
|
"git.cryptic.systems/fh-trier/go-flucky/pkg/config"
|
2018-11-19 21:36:21 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-11-28 11:41:50 +00:00
|
|
|
var enabled bool
|
|
|
|
|
2018-11-19 21:36:21 +00:00
|
|
|
var addRemoteCmd = &cobra.Command{
|
|
|
|
Use: "add",
|
2018-11-21 19:48:10 +00:00
|
|
|
Short: "Add Remove Server",
|
2018-11-19 21:36:21 +00:00
|
|
|
Args: cobra.ExactArgs(2),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
2019-02-17 17:23:59 +00:00
|
|
|
// read configuration
|
|
|
|
fc, err := config.Read(cfg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create new remote struct
|
|
|
|
remote := config.Remote{
|
2018-11-19 21:36:21 +00:00
|
|
|
Name: args[0],
|
|
|
|
Address: args[1],
|
2018-11-28 11:41:50 +00:00
|
|
|
Enabled: enabled,
|
2018-11-19 21:36:21 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 17:23:59 +00:00
|
|
|
// // add remote entry to list
|
|
|
|
err = fc.AddRemote(&remote)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
2018-11-19 21:36:21 +00:00
|
|
|
}
|
2019-02-17 17:23:59 +00:00
|
|
|
|
|
|
|
// save new configuration
|
|
|
|
err = config.Write(fc, cfg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2018-11-19 21:36:21 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
remoteCmd.AddCommand(addRemoteCmd)
|
2019-02-17 17:23:59 +00:00
|
|
|
addRemoteCmd.Flags().BoolVarP(&enabled, "enable", "e", true, "Enable")
|
2018-11-19 21:36:21 +00:00
|
|
|
}
|