52 lines
945 B
Go
52 lines
945 B
Go
package remote
|
|
|
|
import (
|
|
"log"
|
|
|
|
"git.cryptic.systems/fh-trier/go-flucky/pkg/config"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var enabled bool
|
|
|
|
var addRemoteCmd = &cobra.Command{
|
|
Use: "add",
|
|
Short: "Add Remote Server",
|
|
Args: cobra.ExactArgs(2),
|
|
Aliases: []string{"append"},
|
|
Example: "flucky remote add origin https://example.local",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
// read configuration
|
|
fc, err := config.Read(cfg)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
// create new remote struct
|
|
remote := config.Remote{
|
|
Name: args[0],
|
|
Address: args[1],
|
|
Enabled: enabled,
|
|
}
|
|
|
|
// // add remote entry to list
|
|
err = fc.AddRemote(&remote)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
// save new configuration
|
|
err = config.Write(fc, cfg)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
remoteCmd.AddCommand(addRemoteCmd)
|
|
addRemoteCmd.Flags().BoolVarP(&enabled, "enable", "e", true, "Enable")
|
|
}
|