@@ -17,12 +17,14 @@ package commands
17
17
import (
18
18
"context"
19
19
"fmt"
20
+ "os"
20
21
"time"
21
22
22
23
"github.com/codefresh-io/cli-v2/pkg/log"
23
24
"github.com/codefresh-io/cli-v2/pkg/runtime"
24
25
"github.com/codefresh-io/cli-v2/pkg/store"
25
26
"github.com/codefresh-io/cli-v2/pkg/util"
27
+ "github.com/juju/ansiterm"
26
28
27
29
apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
28
30
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
@@ -66,6 +68,7 @@ func NewGitSourceCommand() *cobra.Command {
66
68
}
67
69
68
70
cmd .AddCommand (NewGitSourceCreateCommand ())
71
+ cmd .AddCommand (NewGitSourceListCommand ())
69
72
cmd .AddCommand (NewGitSourceDeleteCommand ())
70
73
71
74
return cmd
@@ -132,6 +135,58 @@ func NewGitSourceCreateCommand() *cobra.Command {
132
135
return cmd
133
136
}
134
137
138
+ func NewGitSourceListCommand () * cobra.Command {
139
+ cmd := & cobra.Command {
140
+ Use : "list runtime_name" ,
141
+ Short : "List all Codefresh git-sources of a given runtime" ,
142
+ Example : util .Doc (`<BIN> git-source list my-runtime` ),
143
+ RunE : func (_ * cobra.Command , args []string ) error {
144
+ return RunGitSourceList (args [0 ])
145
+ },
146
+ }
147
+ return cmd
148
+ }
149
+
150
+ func RunGitSourceList (runtimeName string ) error {
151
+ gitSources , err := cfConfig .NewClient ().GitSource ().List (runtimeName )
152
+
153
+ if err != nil {
154
+ return fmt .Errorf ("failed to get git-sources list. Err: %w" , err )
155
+ }
156
+
157
+ tb := ansiterm .NewTabWriter (os .Stdout , 0 , 0 , 4 , ' ' , 0 )
158
+ _ , err = fmt .Fprintln (tb , "NAME\t REPOURL\t PATH\t HEALTH-STATUS\t SYNC-STATUS" )
159
+ if err != nil {
160
+ return fmt .Errorf ("failed to print git-source list table headers. Err: %w" , err )
161
+ }
162
+
163
+ for _ , gs := range gitSources {
164
+ name := gs .Metadata .Name
165
+ repoURL := gs .Self .RepoURL
166
+ path := gs .Self .Path
167
+ healthStatus := "N/A"
168
+ syncStatus := gs .Self .Status .SyncStatus .String ()
169
+
170
+ if gs .Self .Status .HealthStatus != nil {
171
+ healthStatus = gs .Self .Status .HealthStatus .String ()
172
+ }
173
+
174
+ _ , err = fmt .Fprintf (tb , "%s\t %s\t %s\t %s\t %s\n " ,
175
+ name ,
176
+ repoURL ,
177
+ path ,
178
+ healthStatus ,
179
+ syncStatus ,
180
+ )
181
+
182
+ if err != nil {
183
+ return err
184
+ }
185
+ }
186
+
187
+ return tb .Flush ()
188
+ }
189
+
135
190
func NewGitSourceDeleteCommand () * cobra.Command {
136
191
var (
137
192
cloneOpts * git.CloneOptions
@@ -182,7 +237,6 @@ func RunCreateGitSource(ctx context.Context, opts *GitSourceCreateOptions) error
182
237
}
183
238
184
239
fi , err := gsFs .ReadDir ("." )
185
-
186
240
if err != nil {
187
241
return fmt .Errorf ("failed to read files in git-source repo. Err: %w" , err )
188
242
}
0 commit comments