99
1010 "github.com/Clever/microplane/clone"
1111 "github.com/Clever/microplane/initialize"
12+ "github.com/Clever/microplane/lib"
1213 "github.com/Clever/microplane/merge"
1314 "github.com/Clever/microplane/plan"
1415 "github.com/Clever/microplane/push"
@@ -33,30 +34,22 @@ var statusCmd = &cobra.Command{
3334 log .Fatalf ("error loading init.json: %s\n " , err .Error ())
3435 }
3536
36- singleRepo , err := cmd .Flags ().GetString ("repo" )
37- if err == nil && singleRepo != "" {
38- valid := false
39- validRepoNames := []string {}
40- for _ , r := range initOutput .Repos {
41- if r .Name == singleRepo {
42- valid = true
43- break
44- }
45- validRepoNames = append (validRepoNames , r .Name )
46- }
47- if ! valid {
48- log .Fatalf ("%s not a targeted repo name (valid target repos are: %s)" , singleRepo , strings .Join (validRepoNames , ", " ))
49- }
50- isSingleRepo = true
37+ repos , err := whichRepos (cmd )
38+ if err != nil {
39+ log .Fatal (err )
5140 }
52-
53- repos := []string {}
54- for _ , r := range initOutput .Repos {
55- if singleRepo != "" && r .Name != singleRepo {
56- continue
41+ sync , err := cmd .Flags ().GetBool ("sync" )
42+ if err != nil {
43+ log .Fatal (err )
44+ }
45+ if sync {
46+ err = parallelize (repos , syncOneRepo )
47+ if err != nil {
48+ // TODO: dig into errors and display them with more detail
49+ log .Fatal (err )
5750 }
58- repos = append (repos , r .Name )
5951 }
52+
6053 printStatus (repos )
6154 },
6255}
@@ -76,7 +69,7 @@ func joinWithTab(s ...string) string {
7669 return strings .Join (s , "\t " )
7770}
7871
79- func printStatus (repos []string ) {
72+ func printStatus (repos []lib. Repo ) {
8073 out := tabWriterWithDefaults ()
8174 fmt .Fprintln (out , joinWithTab ("REPO" , "STATUS" , "DETAILS" ))
8275 for _ , r := range repos {
@@ -86,19 +79,20 @@ func printStatus(repos []string) {
8679 if len (d3 ) > 150 {
8780 d3 = d3 [:150 ] + "..."
8881 }
89- fmt .Fprintln (out , joinWithTab (r , status , d3 ))
82+ fmt .Fprintln (out , joinWithTab (r . Name , status , d3 ))
9083 }
9184 out .Flush ()
9285}
9386
94- func getRepoStatus (repo string ) (status , details string ) {
87+ func getRepoStatus (repo lib.Repo ) (status , details string ) {
88+ repoName := repo .Name
9589 status = "initialized"
9690 details = ""
9791 var cloneOutput struct {
9892 clone.Output
9993 Error string
10094 }
101- if ! (loadJSON (outputPath (repo , "clone" ), & cloneOutput ) == nil && cloneOutput .Success ) {
95+ if ! (loadJSON (outputPath (repoName , "clone" ), & cloneOutput ) == nil && cloneOutput .Success ) {
10296 if cloneOutput .Error != "" {
10397 details = color .RedString ("(clone error) " ) + cloneOutput .Error
10498 }
@@ -110,7 +104,7 @@ func getRepoStatus(repo string) (status, details string) {
110104 plan.Output
111105 Error string
112106 }
113- if ! (loadJSON (outputPath (repo , "plan" ), & planOutput ) == nil && planOutput .Success ) {
107+ if ! (loadJSON (outputPath (repoName , "plan" ), & planOutput ) == nil && planOutput .Success ) {
114108 if planOutput .Error != "" {
115109 details = color .RedString ("(plan error) " ) + planOutput .Error
116110 }
@@ -129,7 +123,7 @@ func getRepoStatus(repo string) (status, details string) {
129123 push.Output
130124 Error string
131125 }
132- if ! (loadJSON (outputPath (repo , "push" ), & pushOutput ) == nil && pushOutput .Success ) {
126+ if ! (loadJSON (outputPath (repoName , "push" ), & pushOutput ) == nil && pushOutput .Success ) {
133127 if pushOutput .Error != "" {
134128 details = color .RedString ("(push error) " ) + pushOutput .Error
135129 }
@@ -142,7 +136,8 @@ func getRepoStatus(repo string) (status, details string) {
142136 merge.Output
143137 Error string
144138 }
145- if ! (loadJSON (outputPath (repo , "merge" ), & mergeOutput ) == nil && mergeOutput .Success ) {
139+ // check PR was merged
140+ if ! (loadJSON (outputPath (repoName , "merge" ), & mergeOutput ) == nil && mergeOutput .Success ) {
146141 if mergeOutput .Error != "" {
147142 details = color .RedString ("(merge error) " ) + mergeOutput .Error
148143 }
0 commit comments