File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 "fmt"
99 "gh_foundations/internal/pkg/functions"
1010 "os"
11+ "strings"
1112
1213 "github.com/spf13/cobra"
1314)
@@ -24,7 +25,7 @@ var OrgsCmd = &cobra.Command{
2425 return nil
2526 },
2627 Run : func (cmd * cobra.Command , args []string ) {
27-
28+
2829 orgsDir := args [0 ]
2930
3031 orgs , err := functions .FindManagedOrgs (orgsDir )
@@ -33,16 +34,11 @@ var OrgsCmd = &cobra.Command{
3334 os .Exit (1 )
3435 }
3536
36- var orgOut string
37- orgOut = ""
38- for _ , org := range orgs {
39- if orgOut != "" {
40- orgOut = fmt .Sprintf ("%s, '%s'" , orgOut , org )
41- } else {
42- orgOut = fmt .Sprintf ("['%s'" , org )
43- }
37+ var orgOut string = "[]"
38+
39+ if len (orgs ) > 0 {
40+ orgOut = fmt .Sprintf ("['%s']" , strings .Join (orgs , "', '" ))
4441 }
45- orgOut = fmt .Sprintf ("%s]" , orgOut )
4642
4743 fmt .Println (orgOut )
4844
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
1010 "gh_foundations/internal/pkg/types/status"
1111 "log"
1212 "os"
13+ "strings"
1314
1415 "github.com/spf13/cobra"
1516)
@@ -36,21 +37,19 @@ var ReposCmd = &cobra.Command{
3637 if err != nil {
3738 log .Fatalf ("Error in findManagedRepos: %s" , err )
3839 }
39-
40+
41+ repoList := flattenRepos (orgSet )
42+
4043 if ghas {
4144 orgSet = orgSet .WithGHASEnabled ()
42- log .Printf ("Found %d repositories with GHAS enabled\n " , len (flattenRepos (orgSet )))
45+ repoList = flattenRepos (orgSet )
46+ log .Printf ("Found %d repositories with GHAS enabled\n " , len (repoList ))
4347 }
44- var repos string
45- repos = ""
46- for _ , repo := range flattenRepos (orgSet ) {
47- if repos != "" {
48- repos = fmt .Sprintf ("%s, '%s'" , repos , repo )
49- } else {
50- repos = fmt .Sprintf ("['%s'" , repo )
51- }
48+
49+ repos := "[]"
50+ if len (repoList ) > 0 {
51+ repos = fmt .Sprintf ("['%s']" , strings .Join (repoList , "', '" ))
5252 }
53- repos = fmt .Sprintf ("%s]" , repos )
5453
5554 fmt .Println (repos )
5655 },
@@ -80,4 +79,4 @@ func flattenRepos(org status.OrgSet) []string {
8079 }
8180 }
8281 return repoNames
83- }
82+ }
You can’t perform that action at this time.
0 commit comments