Skip to content

Commit eb53491

Browse files
author
Joshua Anderson
committed
feat(client-go): add git endpoint
1 parent bd230bb commit eb53491

4 files changed

Lines changed: 84 additions & 1 deletion

File tree

client-go/cmd/git.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cmd
2+
3+
// GitRemote creates a git remote for a deis app.
4+
func GitRemote(appID, remote string) error {
5+
c, appID, err := load(appID)
6+
7+
if err != nil {
8+
return err
9+
}
10+
11+
return c.CreateRemote(remote, appID)
12+
}

client-go/controller/client/git.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,31 @@ package client
33
import (
44
"errors"
55
"fmt"
6+
"io/ioutil"
67
"os/exec"
78
"strings"
89
)
910

1011
// CreateRemote adds a git remote in the current directory.
1112
func (c Client) CreateRemote(remote, appID string) error {
12-
_, err := exec.Command("git", "remote", "add", remote, c.RemoteURL(appID)).Output()
13+
cmd := exec.Command("git", "remote", "add", remote, c.RemoteURL(appID))
14+
stderr, err := cmd.StderrPipe()
1315

1416
if err != nil {
1517
return err
1618
}
1719

20+
if err = cmd.Start(); err != nil {
21+
return err
22+
}
23+
24+
output, _ := ioutil.ReadAll(stderr)
25+
fmt.Print(string(output))
26+
27+
if err := cmd.Wait(); err != nil {
28+
return err
29+
}
30+
1831
fmt.Printf("Git remote %s added\n", remote)
1932

2033
return nil

client-go/deis.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Use 'git push deis master' to deploy to an application.
9191
err = parser.Builds(argv)
9292
case "keys":
9393
err = parser.Keys(argv)
94+
case "git":
95+
err = parser.Git(argv)
9496
case "users":
9597
err = parser.Users(argv)
9698
case "help":

client-go/parser/git.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package parser
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
7+
"github.com/deis/deis/client-go/cmd"
8+
docopt "github.com/docopt/docopt-go"
9+
)
10+
11+
// Git routes git commands to their specific function.
12+
func Git(argv []string) error {
13+
usage := `
14+
Valid commands for git:
15+
16+
git:remote Adds git remote of application to repository
17+
18+
Use 'deis help [command]' to learn more.
19+
`
20+
if len(argv) < 2 {
21+
return errors.New("'deis git' is not a valid command, try 'deis help git'")
22+
}
23+
24+
switch argv[1] {
25+
case "remote":
26+
return gitRemote(combineCommand(argv))
27+
case "--help":
28+
fmt.Print(usage)
29+
return nil
30+
default:
31+
PrintUsage()
32+
return nil
33+
}
34+
}
35+
36+
func gitRemote(argv []string) error {
37+
usage := `
38+
Adds git remote of application to repository
39+
40+
Usage: deis git:remote [options]
41+
42+
Options:
43+
-a --app=<app>
44+
the uniquely identifiable name for the application.
45+
-r --remote=REMOTE
46+
name of remote to create. [default: deis]
47+
`
48+
49+
args, err := docopt.Parse(usage, argv, true, "", false, true)
50+
51+
if err != nil {
52+
return err
53+
}
54+
55+
return cmd.GitRemote(safeGetValue(args, "--app"), args["--remote"].(string))
56+
}

0 commit comments

Comments
 (0)