1
- package main
1
+ package cmd
2
2
3
3
import (
4
4
"bufio"
5
- "github.com/gruntwork-io/go-commons/errors"
6
- "github.com/gruntwork-io/go-commons/logging"
7
- "github.com/urfave/cli"
8
5
"io"
9
6
"os"
10
7
"strings"
11
- )
12
-
13
- // GitXargsConfig is the internal representation of a given git-xargs run as specified by the user
14
- type GitXargsConfig struct {
15
- DryRun bool
16
- SkipPullRequests bool
17
- BranchName string
18
- CommitMessage string
19
- PullRequestTitle string
20
- PullRequestDescription string
21
- ReposFile string
22
- GithubOrg string
23
- RepoSlice []string
24
- RepoFromStdIn []string
25
- Args []string
26
- GithubClient GithubClient
27
- GitClient GitClient
28
- Stats * RunStats
29
- }
30
8
31
- // NewGitXargsConfig sets reasonable defaults for a GitXargsConfig and returns a pointer to a the config
32
- func NewGitXargsConfig () * GitXargsConfig {
33
- return & GitXargsConfig {
34
- DryRun : false ,
35
- SkipPullRequests : false ,
36
- BranchName : "" ,
37
- CommitMessage : DefaultCommitMessage ,
38
- PullRequestTitle : DefaultPullRequestTitle ,
39
- PullRequestDescription : DefaultPullRequestDescription ,
40
- ReposFile : "" ,
41
- GithubOrg : "" ,
42
- RepoSlice : []string {},
43
- RepoFromStdIn : []string {},
44
- Args : []string {},
45
- GithubClient : configureGithubClient (),
46
- GitClient : NewGitClient (GitProductionProvider {}),
47
- Stats : NewStatsTracker (),
48
- }
49
- }
9
+ "github.com/gruntwork-io/git-xargs/auth"
10
+ "github.com/gruntwork-io/git-xargs/config"
11
+ gitxargs_io "github.com/gruntwork-io/git-xargs/io"
12
+ "github.com/gruntwork-io/git-xargs/repository"
13
+ "github.com/gruntwork-io/git-xargs/types"
14
+ "github.com/gruntwork-io/go-commons/errors"
15
+ "github.com/gruntwork-io/go-commons/logging"
16
+ "github.com/urfave/cli"
17
+ )
50
18
51
19
// parseGitXargsConfig accepts a urfave cli context and binds its values
52
20
// to an internal representation of the data supplied by the user
53
- func parseGitXargsConfig (c * cli.Context ) (* GitXargsConfig , error ) {
54
- config := NewGitXargsConfig ()
21
+ func parseGitXargsConfig (c * cli.Context ) (* config. GitXargsConfig , error ) {
22
+ config := config . NewGitXargsConfig ()
55
23
config .DryRun = c .Bool ("dry-run" )
56
24
config .SkipPullRequests = c .Bool ("skip-pull-requests" )
57
25
config .BranchName = c .String ("branch-name" )
@@ -117,14 +85,14 @@ func parseSliceFromReader(reader io.Reader) ([]string, error) {
117
85
118
86
// handleRepoProcessing encapsulates the main processing logic for the supplied repos and printing the run report that
119
87
// is built up throughout the processing
120
- func handleRepoProcessing (config * GitXargsConfig ) error {
88
+ func handleRepoProcessing (config * config. GitXargsConfig ) error {
121
89
// Track whether or not pull requests were skipped
122
90
config .Stats .SetSkipPullRequests (config .SkipPullRequests )
123
91
124
92
// Update raw command supplied
125
93
config .Stats .SetCommand (config .Args )
126
94
127
- if err := OperateOnRepos (config ); err != nil {
95
+ if err := repository . OperateOnRepos (config ); err != nil {
128
96
return err
129
97
}
130
98
@@ -138,24 +106,24 @@ func handleRepoProcessing(config *GitXargsConfig) error {
138
106
// 1. An exported GITHUB_OAUTH_TOKEN
139
107
// 2. Arguments passed to the binary itself which should be executed against the targeted repos
140
108
// 3. At least one of the three valid methods for selecting repositories
141
- func sanityCheckInputs (config * GitXargsConfig ) error {
142
- if err := ensureGithubOauthTokenSet (); err != nil {
109
+ func sanityCheckInputs (config * config. GitXargsConfig ) error {
110
+ if err := auth . EnsureGithubOauthTokenSet (); err != nil {
143
111
return err
144
112
}
145
113
146
114
if len (config .Args ) < 1 {
147
- return errors .WithStackTrace (NoArgumentsPassedErr {})
115
+ return errors .WithStackTrace (types. NoArgumentsPassedErr {})
148
116
}
149
117
150
- if err := ensureValidOptionsPassed (config ); err != nil {
118
+ if err := gitxargs_io . EnsureValidOptionsPassed (config ); err != nil {
151
119
return errors .WithStackTrace (err )
152
120
}
153
121
154
122
return nil
155
123
}
156
124
157
125
// runGitXargs is the urfave cli app's Action that is called when the user executes the binary
158
- func runGitXargs (c * cli.Context ) error {
126
+ func RunGitXargs (c * cli.Context ) error {
159
127
// If someone calls us with no args at all, show the help text and exit
160
128
if ! c .Args ().Present () {
161
129
return cli .ShowAppHelp (c )
0 commit comments