99 "cuelang.org/go/cue"
1010 "github.com/input-output-hk/catalyst-forge/cli/pkg/run"
1111 "github.com/input-output-hk/catalyst-forge/cli/pkg/scan"
12+ "github.com/input-output-hk/catalyst-forge/cli/pkg/utils"
1213 "golang.org/x/exp/maps"
1314)
1415
@@ -55,14 +56,14 @@ func (c *ScanCmd) Run(ctx run.RunContext) error {
5556 }
5657 }
5758
58- printJson (result , c .Pretty )
59+ utils . PrintJson (result , c .Pretty )
5960 case c .Blueprint :
6061 result := make (map [string ]cue.Value )
6162 for path , project := range projects {
6263 result [path ] = project .Raw ().Value ()
6364 }
6465
65- printJson (result , c .Pretty )
66+ utils . PrintJson (result , c .Pretty )
6667 case c .Earthfile && len (c .Filter ) > 0 :
6768 result := make (map [string ]map [string ][]string )
6869 for _ , filter := range c .Filter {
@@ -97,9 +98,9 @@ func (c *ScanCmd) Run(ctx run.RunContext) error {
9798 sort .Strings (enumerated [filter ])
9899 }
99100
100- printJson (enumerated , c .Pretty )
101+ utils . PrintJson (enumerated , c .Pretty )
101102 } else {
102- printJson (result , c .Pretty )
103+ utils . PrintJson (result , c .Pretty )
103104 }
104105 case c .Earthfile :
105106 result := make (map [string ][]string )
@@ -112,15 +113,27 @@ func (c *ScanCmd) Run(ctx run.RunContext) error {
112113 if ctx .CI {
113114 enumerated := enumerate (result )
114115 sort .Strings (enumerated )
115- printJson (enumerated , c .Pretty )
116+ utils . PrintJson (enumerated , c .Pretty )
116117 } else {
117- printJson (result , c .Pretty )
118+ utils . PrintJson (result , c .Pretty )
118119 }
119120 default :
120121 keys := maps .Keys (projects )
121122 sort .Strings (keys )
122- printJson (keys , c .Pretty )
123+ utils . PrintJson (keys , c .Pretty )
123124 }
124125
125126 return nil
126127}
128+
129+ // enumerate enumerates the Earthfile+Target pairs from the target map.
130+ func enumerate (data map [string ][]string ) []string {
131+ var result []string
132+ for path , targets := range data {
133+ for _ , target := range targets {
134+ result = append (result , fmt .Sprintf ("%s+%s" , path , target ))
135+ }
136+ }
137+
138+ return result
139+ }
0 commit comments