hub/commands/remote.go

56 строки
1.3 KiB
Go
Исходник Обычный вид История

2013-06-13 18:11:05 +04:00
package commands
import (
2013-06-18 00:35:02 +04:00
"github.com/jingweno/gh/git"
2013-06-13 18:11:05 +04:00
"github.com/jingweno/gh/github"
"github.com/jingweno/gh/utils"
)
2013-06-14 21:05:47 +04:00
var cmdRemote = &Command{
2013-06-18 00:56:57 +04:00
Run: remote,
GitExtension: true,
Usage: "remote [-p] OPTIONS USER[/REPOSITORY]",
Short: "View and manage a set of remote repositories",
2013-06-13 18:11:05 +04:00
}
2013-06-18 00:35:02 +04:00
/**
$ gh remote add jingweno
> git remote add jingweno git://github.com/jingweno/THIS_REPO.git
2013-06-18 00:35:02 +04:00
$ gh remote add -p jingweno
> git remote add jingweno git@github.com:jingweno/THIS_REPO.git
2013-06-13 18:11:05 +04:00
2013-06-18 00:35:02 +04:00
$ gh remote add origin
> git remote add origin
git://github.com/YOUR_LOGIN/THIS_REPO.git
**/
2013-06-14 21:05:47 +04:00
func remote(command *Command, args []string) {
if len(args) >= 2 && (args[0] == "add" || args[0] == "set-url") {
2013-06-18 00:35:02 +04:00
args = transformRemoteArgs(args)
2013-06-13 18:11:05 +04:00
}
2013-06-25 01:40:05 +04:00
err := git.SysExec("remote", args...)
2013-06-18 00:35:02 +04:00
utils.Check(err)
}
func transformRemoteArgs(args []string) (newArgs []string) {
args, isPriavte := parseRemotePrivateFlag(args)
newArgs, owner := removeItem(args, len(args)-1)
2013-06-13 18:11:05 +04:00
gh := github.New()
2013-06-18 00:35:02 +04:00
url := gh.ExpandRemoteUrl(owner, isPriavte)
return append(newArgs, owner, url)
}
func parseRemotePrivateFlag(args []string) ([]string, bool) {
for i, arg := range args {
if arg == "-p" {
args, _ = removeItem(args, i)
return args, true
}
}
return args, false
2013-06-13 18:11:05 +04:00
}