Skip to content

Commit fabcac7

Browse files
committed
feature: adding options for clone: target, regexp and auth, adding functions to detect if origin is with https or ssh, adding functions to list directories in WORKING_DIR or WORKING_DIR + target to do local git actions
1 parent 8d2c7d2 commit fabcac7

17 files changed

+246
-126
lines changed

Diff for: cmd/add.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ var addCmd = &cobra.Command{
2727
Short: "Add all content in each repository",
2828
Long: `Add all content to each repository, equivalent to make git add -A.`,
2929
Run: func(cmd *cobra.Command, args []string) {
30-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
31-
myRepos := githelper.MyRepos{}
32-
repoNames := myRepos.GithubGetRepoNames(json_file)
33-
githelper.GitAdd(repoNames)
30+
target, _ := cmd.Flags().GetString("target")
31+
repoNames := githelper.ListDirectories(target)
32+
githelper.GitAdd(target, repoNames)
3433
},
3534
}
3635

Diff for: cmd/checkout.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ var checkoutCmd = &cobra.Command{
2828
Long: `Checkout to a specific branch, you need to pass branch name`,
2929
Run: func(cmd *cobra.Command, args []string) {
3030
branch, _ := cmd.Flags().GetString("branch")
31-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
32-
myRepos := githelper.MyRepos{}
33-
repoNames := myRepos.GithubGetRepoNames(json_file)
34-
githelper.GitCheckout(repoNames, branch)
31+
target, _ := cmd.Flags().GetString("target")
32+
repoNames := githelper.ListDirectories(target)
33+
githelper.GitCheckout(target, repoNames, branch)
3534
},
3635
}
3736

Diff for: cmd/clone.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,28 @@ var cloneCmd = &cobra.Command{
3333
provider, _ := cmd.Flags().GetString("provider")
3434
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
3535
org, _ := cmd.Flags().GetString("org")
36+
regex, _ := cmd.Flags().GetString("regexp")
37+
target, _ := cmd.Flags().GetString("target")
38+
auth, _ := cmd.Flags().GetString("auth")
3639
if provider == "github" && json_file != "" {
3740
myRepos := githelper.MyRepos{}
3841
myRepos = myRepos.GetGithubRepositoriesInfo(org)
3942
err := githelper.WriteReposToJson(myRepos, json_file)
40-
if err != nil {
41-
githelper.CheckIfError(err)
42-
} else {
43-
color.Green("The json file %s with repo info was written sucessfully", json_file)
44-
}
45-
repoNames = myRepos.GithubGetRepoNames(json_file)
46-
repoUrls = myRepos.GithubGetCloneUrls(json_file)
43+
githelper.CheckIfError(err)
44+
color.Green("The json file %s with repo info was written sucessfully", json_file)
45+
repoNames = myRepos.GithubGetRepoNames(json_file, regex)
46+
repoUrls = myRepos.GithubGetGitUrls(json_file, regex, auth)
4747
}
48-
githelper.GitClone(repoNames, repoUrls)
48+
githelper.GitClone(target, auth, repoNames, repoUrls)
4949
},
5050
}
5151

5252
func init() {
5353
rootCmd.AddCommand(cloneCmd)
54-
cloneCmd.PersistentFlags().StringP("provider", "p", "", "A provider to choose, options: gitub, gitlab")
55-
cloneCmd.MarkPersistentFlagRequired("provider")
54+
cloneCmd.PersistentFlags().StringP("provider", "p", "github", "A provider to choose, options: gitub, gitlab")
55+
//cloneCmd.MarkPersistentFlagRequired("provider")
5656
cloneCmd.PersistentFlags().StringP("org", "o", "", "The github Organization to work with")
57+
cloneCmd.PersistentFlags().StringP("regexp", "r", "", "Regexp to apply to repositories clone process, to clone based on it")
58+
cloneCmd.PersistentFlags().StringP("auth", "a", "ssh", "Select if you want to clone using HTTPS or SSH.")
59+
cloneCmd.PersistentFlags().String("repo-info-json-file", "repos_info.json", "The name of the json file with info of the repos of the Github Org. It is read for each git local actions.")
5760
}

Diff for: cmd/commit.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ var commitCmd = &cobra.Command{
2828
Long: `Create a commit to each repository.`,
2929
Run: func(cmd *cobra.Command, args []string) {
3030
message, _ := cmd.Flags().GetString("message")
31-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
32-
myRepos := githelper.MyRepos{}
33-
repoNames := myRepos.GithubGetRepoNames(json_file)
34-
githelper.GitCommit(repoNames, message)
31+
target, _ := cmd.Flags().GetString("target")
32+
repoNames := githelper.ListDirectories(target)
33+
githelper.GitCommit(target, repoNames, message)
3534
},
3635
}
3736

Diff for: cmd/createBranch.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ var createBranchCmd = &cobra.Command{
2828
Long: `Create a branch locally and checkout into that branch for each repository.`,
2929
Run: func(cmd *cobra.Command, args []string) {
3030
branch, _ := cmd.Flags().GetString("branch")
31-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
32-
myRepos := githelper.MyRepos{}
33-
repoNames := myRepos.GithubGetRepoNames(json_file)
34-
githelper.GitCreateBranch(repoNames, branch)
31+
target, _ := cmd.Flags().GetString("target")
32+
repoNames := githelper.ListDirectories(target)
33+
githelper.GitCreateBranch(target, repoNames, branch)
3534
},
3635
}
3736

Diff for: cmd/fetch.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ var fetchCmd = &cobra.Command{
2727
Short: "Do a git fetch of all branches on each repo",
2828
Long: `Do a git fetch of all branches on each repo. Equivalent to do: git fetch --all.`,
2929
Run: func(cmd *cobra.Command, args []string) {
30-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
31-
myRepos := githelper.MyRepos{}
32-
repoNames := myRepos.GithubGetRepoNames(json_file)
33-
githelper.GitFetch(repoNames)
30+
target, _ := cmd.Flags().GetString("target")
31+
repoNames := githelper.ListDirectories(target)
32+
githelper.GitFetch(target, repoNames)
3433
},
3534
}
3635

Diff for: cmd/pr.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,18 @@ var prCmd = &cobra.Command{
3535
create, _ := cmd.Flags().GetBool("create")
3636
update, _ := cmd.Flags().GetBool("update")
3737
merge, _ := cmd.Flags().GetBool("merge")
38+
target, _ := cmd.Flags().GetString("target")
3839

3940
repos := githelper.MyRepos{}
40-
repoNames := repos.GithubGetRepoNames(repos_json_file)
41+
repoNames := githelper.ListDirectories(target)
4142
org := repos.GithubGetOrg(repos_json_file)
4243

4344
myPrs := githelper.MyPrs{}
4445
if create {
4546
myPrs = myPrs.GithubCreatePr(org, repoNames, new_pr_json_file, reviewers)
4647
err := githelper.WritePrsToJson(myPrs, pr_info_json_file)
47-
if err != nil {
48-
githelper.CheckIfError(err)
49-
} else {
50-
color.Green("The json file %s with pr info was written sucessfully", pr_info_json_file)
51-
}
48+
githelper.CheckIfError(err)
49+
color.Green("The json file %s with pr info was written sucessfully", pr_info_json_file)
5250
} else if update {
5351
myPrs.GithubEditPr(org, repoNames, pr_info_json_file)
5452
} else if merge {

Diff for: cmd/pull.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ var pullCmd = &cobra.Command{
2727
Short: "Pull changes of a branch from remote",
2828
Long: `Pull changes of a branch from remote. It will make the pull of current branch`,
2929
Run: func(cmd *cobra.Command, args []string) {
30-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
31-
myRepos := githelper.MyRepos{}
32-
repoNames := myRepos.GithubGetRepoNames(json_file)
33-
githelper.GitPull(repoNames)
30+
target, _ := cmd.Flags().GetString("target")
31+
repoNames := githelper.ListDirectories(target)
32+
githelper.GitPull(target, repoNames)
3433
},
3534
}
3635

Diff for: cmd/push.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ var pushCmd = &cobra.Command{
2727
Short: "Push changes of a branch to remote",
2828
Long: `Push changes of a branch from remote. It will make the Push of current branch.`,
2929
Run: func(cmd *cobra.Command, args []string) {
30-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
31-
myRepos := githelper.MyRepos{}
32-
repoNames := myRepos.GithubGetRepoNames(json_file)
33-
githelper.GitPush(repoNames)
30+
target, _ := cmd.Flags().GetString("target")
31+
repoNames := githelper.ListDirectories(target)
32+
githelper.GitPush(target, repoNames)
3433
},
3534
}
3635

Diff for: cmd/rebase.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ If you have conflicts you can pass the argument with "continue" or "abort" optio
3232
Run: func(cmd *cobra.Command, args []string) {
3333
fmt.Println("rebase called")
3434
base_branch, _ := cmd.Flags().GetString("base-branch")
35-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
36-
myRepos := githelper.MyRepos{}
37-
repoNames := myRepos.GithubGetRepoNames(json_file)
38-
githelper.GitRebase(repoNames, base_branch)
35+
target, _ := cmd.Flags().GetString("target")
36+
repoNames := githelper.ListDirectories(target)
37+
githelper.GitRebase(target, repoNames, base_branch)
3938
},
4039
}
4140

Diff for: cmd/repository.go

+1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ func init() {
4242
repoCmd.PersistentFlags().StringP("provider", "p", "", "A provider to choose, options: gitub, gitlab")
4343
repoCmd.MarkPersistentFlagRequired("provider")
4444
repoCmd.PersistentFlags().BoolP("create", "c", false, "Create the repositories from repo-info-json-file")
45+
repoCmd.PersistentFlags().String("repo-info-json-file", "repos_info.json", "The name of the json file with info of the repos of the Github Org. It is read for each git local actions.")
4546
}

Diff for: cmd/reset.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ var resetCmd = &cobra.Command{
2727
Short: "Hard Reset to HEAD in all repositories",
2828
Long: `Hard Reset to HEAD in all repositories.`,
2929
Run: func(cmd *cobra.Command, args []string) {
30-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
31-
myRepos := githelper.MyRepos{}
32-
repoNames := myRepos.GithubGetRepoNames(json_file)
33-
githelper.GitReset(repoNames)
30+
target, _ := cmd.Flags().GetString("target")
31+
repoNames := githelper.ListDirectories(target)
32+
githelper.GitReset(target, repoNames)
3433
},
3534
}
3635

Diff for: cmd/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ func init() {
5757
// Cobra also supports local flags, which will only run
5858
// when this action is called directly.
5959
cobra.OnInitialize(githelper.ValidateEnv)
60-
rootCmd.PersistentFlags().String("repo-info-json-file", "repos_info.json", "The name of the json file with info of the repos of the Github Org or Gitlab Group. It is read for each git local actions.")
60+
rootCmd.PersistentFlags().StringP("target", "t", "", "Target directory inside your working directory where git actions will be executed. If not set actions will be done on WORKING_DIR")
6161
}

Diff for: cmd/status.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ var statusCmd = &cobra.Command{
2727
Short: "Print the working tree status of each repository",
2828
Long: `Print the working tree status of each repository. Equivalent to do git status`,
2929
Run: func(cmd *cobra.Command, args []string) {
30-
json_file, _ := cmd.Flags().GetString("repo-info-json-file")
31-
myRepos := githelper.MyRepos{}
32-
repoNames := myRepos.GithubGetRepoNames(json_file)
33-
githelper.GitStatus(repoNames)
30+
target, _ := cmd.Flags().GetString("target")
31+
repoNames := githelper.ListDirectories(target)
32+
githelper.GitStatus(target, repoNames)
3433
},
3534
}
3635

0 commit comments

Comments
 (0)