@@ -17,13 +17,15 @@ 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/cdUtils"
23
24
"github.com/codefresh-io/cli-v2/pkg/eventUtils"
24
25
"github.com/codefresh-io/cli-v2/pkg/log"
25
26
"github.com/codefresh-io/cli-v2/pkg/store"
26
27
"github.com/codefresh-io/cli-v2/pkg/util"
28
+ "github.com/juju/ansiterm"
27
29
28
30
appset "github.com/argoproj-labs/applicationset/api/v1alpha1"
29
31
apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
@@ -74,6 +76,7 @@ func NewRuntimeCommand() *cobra.Command {
74
76
}
75
77
76
78
cmd .AddCommand (NewRuntimeCreateCommand ())
79
+ cmd .AddCommand (NewRuntimeListCommand ())
77
80
cmd .AddCommand (NewRuntimeDeleteCommand ())
78
81
79
82
return cmd
@@ -195,6 +198,65 @@ func RunRuntimeCreate(ctx context.Context, opts *RuntimeCreateOptions) error {
195
198
return nil
196
199
}
197
200
201
+ func NewRuntimeListCommand () * cobra.Command {
202
+
203
+
204
+ cmd := & cobra.Command {
205
+ Use : "list " ,
206
+ Short : "List all Codefresh runtimes" ,
207
+ Example : util .Doc (`<BIN> runtime list` ),
208
+ RunE : func (cmd * cobra.Command , args []string ) error {
209
+ return listRuntimes (cmd .Context ())
210
+ },
211
+ }
212
+ return cmd
213
+ }
214
+
215
+ func listRuntimes (ctx context.Context ) error {
216
+ runtimes , err := cfConfig .NewClient ().ArgoRuntime ().List ()
217
+ if err != nil {
218
+ return err
219
+ }
220
+ tb := ansiterm .NewTabWriter (os .Stdout , 0 , 0 , 4 , ' ' , 0 )
221
+ _ , err = fmt .Fprintln (tb , "NAME\t NAMESPACE\t CLUSTER\t STATUS\t VERSION" )
222
+ if err != nil {
223
+ return err
224
+ }
225
+ for _ , rt := range runtimes {
226
+ status := "N/A"
227
+ namespace := "N/A"
228
+ name := "N/A"
229
+ cluster := "N/A"
230
+ version := "N/A"
231
+ if rt .Status != nil {
232
+ status = rt .Status .String ()
233
+ }
234
+ if rt .Namespace != nil {
235
+ namespace = * rt .Namespace
236
+ }
237
+ if rt .ObjectMeta != nil && rt .ObjectMeta .Name != nil {
238
+ name = * rt .ObjectMeta .Name
239
+ }
240
+ if rt .Cluster != nil {
241
+ cluster = * rt .Cluster
242
+ }
243
+ if rt .Version != nil {
244
+ version = * rt .Version
245
+ }
246
+ _ , err = fmt .Fprintf (tb , "%s\t %s\t %s\t %s\t %s\n " ,
247
+ name ,
248
+ namespace ,
249
+ cluster ,
250
+ status ,
251
+ version ,
252
+ )
253
+ if err != nil {
254
+ return err
255
+ }
256
+ }
257
+ return tb .Flush ()
258
+ }
259
+
198
260
func NewRuntimeDeleteCommand () * cobra.Command {
199
261
var (
200
262
f kube.Factory
0 commit comments