Skip to content

Commit

Permalink
Set default output directory to org and team names
Browse files Browse the repository at this point in the history
  • Loading branch information
stein committed Jun 18, 2018
1 parent 85c1701 commit 08083ee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions cloner/cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (tC *teamCloner) clone(wg *sync.WaitGroup, sshUrl string, repoName string,

defer wg.Done()
tC.shell.Exec("git", []string{"clone", sshUrl, fmt.Sprintf("%s/%s", dir, repoName)})
fmt.Println(fmt.Sprintf("Finished cloning %s", repoName))
}

func teamId(teams []github.Team, team string) (error, int) {
Expand Down
28 changes: 25 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import (
"github.com/steinfletcher/github-org-clone/shell"
"github.com/steinfletcher/github-org-clone/cloner"
"log"
"fmt"
"time"
)

var (
version = "dev"
commit = ""
date = time.Now().String()
)

func main() {
Expand All @@ -15,9 +23,13 @@ func main() {
app.Name = "github-org-clone"
app.Usage = "clone github team repos"
app.UsageText = "github-org-clone -o MyOrg -t MyTeam"
app.Version = "0.0.1"
app.Version = version
app.EnableBashCompletion = true
app.Description = "A simple cli to clone all the repos managed by a github team"
app.Metadata = map[string]interface{}{
"commit": commit,
"date": date,
}

app.Flags = []cli.Flag {
cli.StringFlag{
Expand All @@ -40,8 +52,7 @@ func main() {
},
cli.StringFlag{
Name: "dir, d",
Usage: "directory to clone into",
Value: "src",
Usage: "directory to clone into. Defaults to the org name or org/team name if defined",
},
}

Expand All @@ -64,6 +75,17 @@ func main() {
die("github organisation (-o) not set", c)
}

if len(dir) == 0 {
if len(team) == 0 {
dir = org
} else {
if _, err := os.Stat(org); os.IsNotExist(err) {
os.Mkdir(org, os.ModePerm)
}
dir = fmt.Sprintf("%s/%s", org, team)
}
}

sh := shell.NewShell()
githubCli := github.NewGithub(username, token)
cl := cloner.NewCloner(githubCli, sh, dir)
Expand Down

0 comments on commit 08083ee

Please sign in to comment.