-
Notifications
You must be signed in to change notification settings - Fork 6
/
removeremotecmd.go
44 lines (39 loc) · 1.25 KB
/
removeremotecmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gincmd
import (
"fmt"
ginclient "github.com/G-Node/gin-cli/ginclient"
"github.com/G-Node/gin-cli/gincmd/ginerrors"
"github.com/G-Node/gin-cli/git"
"github.com/spf13/cobra"
)
func rmRemote(cmd *cobra.Command, args []string) {
if git.Checkwd() == git.NotRepository {
Die(ginerrors.NotInRepo)
}
name := args[0]
err := ginclient.RemoveRemote(name)
CheckError(err)
fmt.Printf(":: Remote removed: %s\n", name)
defremote, _ := ginclient.DefaultRemote()
if defremote == name {
ginclient.UnsetDefaultRemote()
fmt.Printf(":: %s was the default remote. Current default is unset.\n:: Use 'gin use-remote' to set a new default.\n", name)
}
}
// RemoveRemoteCmd sets up the 'remove-remote' repository subcommand
func RemoveRemoteCmd() *cobra.Command {
description := `Remove a remote from the current repository.`
args := map[string]string{
"<name>": "The name of the remote",
}
var cmd = &cobra.Command{
Use: "remove-remote <name>",
Short: "Remove a remote from the current repository",
Long: formatdesc(description, args),
Args: cobra.ExactArgs(1),
Run: rmRemote,
Aliases: []string{"rm-remote"},
DisableFlagsInUseLine: true,
}
return cmd
}