@@ -17,13 +17,15 @@ package commands
1717import (
1818 "context"
1919 "fmt"
20+ "os"
2021 "time"
2122
2223 "github.com/codefresh-io/cli-v2/pkg/cdUtils"
2324 "github.com/codefresh-io/cli-v2/pkg/eventUtils"
2425 "github.com/codefresh-io/cli-v2/pkg/log"
2526 "github.com/codefresh-io/cli-v2/pkg/store"
2627 "github.com/codefresh-io/cli-v2/pkg/util"
28+ "github.com/juju/ansiterm"
2729
2830 appset "github.com/argoproj-labs/applicationset/api/v1alpha1"
2931 apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
@@ -74,6 +76,7 @@ func NewRuntimeCommand() *cobra.Command {
7476 }
7577
7678 cmd .AddCommand (NewRuntimeCreateCommand ())
79+ cmd .AddCommand (NewRuntimeListCommand ())
7780 cmd .AddCommand (NewRuntimeDeleteCommand ())
7881
7982 return cmd
@@ -195,6 +198,65 @@ func RunRuntimeCreate(ctx context.Context, opts *RuntimeCreateOptions) error {
195198 return nil
196199}
197200
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+
198260func NewRuntimeDeleteCommand () * cobra.Command {
199261 var (
200262 f kube.Factory
0 commit comments