PKGBUILD/cmd/remote/add.go

52 lines
945 B
Go
Raw Normal View History

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{
2019-02-22 12:08:58 +00:00
Use: "add",
Short: "Add Remote Server",
Args: cobra.ExactArgs(2),
2019-02-24 21:46:36 +00:00
Aliases: []string{"append"},
2019-02-22 12:08:58 +00:00
Example: "flucky remote add origin https://example.local",
2018-11-19 21:36:21 +00:00
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
}