Skip to content

Commit

Permalink
runtime list command (#16)
Browse files Browse the repository at this point in the history
* runtime list command

* up

* Update cmd/commands/runtime.go

Co-authored-by: Noam Gal <[email protected]>

* update sdk

* wip

* bump

* wip

* wip

* codegen

Co-authored-by: Noam Gal <[email protected]>
  • Loading branch information
oren-codefresh and ATGardner authored Jul 7, 2021
1 parent 9e7eaf6 commit e964202
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ RUN adduser \
--uid 10001 \
codefresh

ARG GITHUB_TOKEN
RUN git config \
--global \
url."https://github:${GITHUB_TOKEN}@github.com".insteadOf \
"https://github.com"
COPY go.mod .
COPY go.sum .

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.0.21
VERSION=v0.0.23
OUT_DIR=dist
YEAR?=$(shell date +"%Y")

Expand Down
62 changes: 62 additions & 0 deletions cmd/commands/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ package commands
import (
"context"
"fmt"
"os"
"time"

"github.com/codefresh-io/cli-v2/pkg/cdUtils"
"github.com/codefresh-io/cli-v2/pkg/eventUtils"
"github.com/codefresh-io/cli-v2/pkg/log"
"github.com/codefresh-io/cli-v2/pkg/store"
"github.com/codefresh-io/cli-v2/pkg/util"
"github.com/juju/ansiterm"

appset "github.com/argoproj-labs/applicationset/api/v1alpha1"
apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
Expand Down Expand Up @@ -74,6 +76,7 @@ func NewRuntimeCommand() *cobra.Command {
}

cmd.AddCommand(NewRuntimeCreateCommand())
cmd.AddCommand(NewRuntimeListCommand())
cmd.AddCommand(NewRuntimeDeleteCommand())

return cmd
Expand Down Expand Up @@ -195,6 +198,65 @@ func RunRuntimeCreate(ctx context.Context, opts *RuntimeCreateOptions) error {
return nil
}

func NewRuntimeListCommand() *cobra.Command {


cmd := &cobra.Command{
Use: "list ",
Short: "List all Codefresh runtimes",
Example: util.Doc(`<BIN> runtime list`),
RunE: func(cmd *cobra.Command, args []string) error {
return listRuntimes(cmd.Context())
},
}
return cmd
}

func listRuntimes(ctx context.Context) error {
runtimes, err := cfConfig.NewClient().ArgoRuntime().List()
if err != nil {
return err
}
tb := ansiterm.NewTabWriter(os.Stdout, 0, 0, 4, ' ', 0)
_, err = fmt.Fprintln(tb, "NAME\tNAMESPACE\tCLUSTER\tSTATUS\tVERSION")
if err != nil {
return err
}
for _, rt := range runtimes {
status := "N/A"
namespace:= "N/A"
name := "N/A"
cluster := "N/A"
version := "N/A"
if rt.Status != nil {
status = rt.Status.String()
}
if rt.Namespace != nil {
namespace = *rt.Namespace
}
if rt.ObjectMeta != nil && rt.ObjectMeta.Name != nil {
name = *rt.ObjectMeta.Name
}
if rt.Cluster != nil {
cluster = *rt.Cluster
}
if rt.Version != nil {
version = *rt.Version
}
_, err = fmt.Fprintf(tb, "%s\t%s\t%s\t%s\t%s\n",
name,
namespace,
cluster,
status,
version,
)
if err != nil {
return err
}
}
return tb.Flush()
}

func NewRuntimeDeleteCommand() *cobra.Command {
var (
f kube.Factory
Expand Down
1 change: 1 addition & 0 deletions docs/commands/cli-v2_runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ cli-v2 runtime [flags]
* [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops
* [cli-v2 runtime create](cli-v2_runtime_create.md) - Create a new Codefresh runtime
* [cli-v2 runtime delete](cli-v2_runtime_delete.md) - Deletes a Codefresh runtime
* [cli-v2 runtime list](cli-v2_runtime_list.md) - List all Codefresh runtimes

33 changes: 33 additions & 0 deletions docs/commands/cli-v2_runtime_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## cli-v2 runtime list

List all Codefresh runtimes

```
cli-v2 runtime list [flags]
```

### Examples

```
cli-v2 runtime list
```

### Options

```
-h, --help help for list
```

### Options inherited from parent commands

```
--auth-context string Run the next command using a specific authentication context
--cfconfig string Custom path for authentication contexts config file (default "/home/user")
--insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io)
--request-timeout duration Request timeout (default 30s)
```

### SEE ALSO

* [cli-v2 runtime](cli-v2_runtime.md) - Manage Codefresh runtimes

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/argoproj/argo-events v1.3.1
github.com/argoproj/argo-workflows/v3 v3.1.0
github.com/briandowns/spinner v1.13.0
github.com/codefresh-io/go-sdk v0.26.2
github.com/codefresh-io/go-sdk v0.26.5
github.com/fatih/color v1.12.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-git/go-billy/v5 v5.3.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ github.com/clusterhq/flocker-go v0.0.0-20160920122132-2b8b7259d313/go.mod h1:P1w
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/codefresh-io/go-sdk v0.26.2 h1:nGiLEOXaYGd7DbwKpqeTm1XXVCATayQm/pU3DwA6wqc=
github.com/codefresh-io/go-sdk v0.26.2/go.mod h1:0m0ATMmbFzvrc3CwUTB10MGO6hydsZdzLeHCAOyAvyM=
github.com/codefresh-io/argo-platform v1.13.0 h1:eWAWkxtO0nGZuekrQJsfFT5KfBMdWby0cOucy4yTExs=
github.com/codefresh-io/argo-platform v1.13.0/go.mod h1:u/eLWAySJ1nRzNWnB5baeyIc5vqINghwYJvydU+EC3c=
github.com/codefresh-io/go-sdk v0.26.5 h1:3apUfIyE4BSGWAwTGwO0yeP0XF4P3VKh7sOqwlDyRSs=
github.com/codefresh-io/go-sdk v0.26.5/go.mod h1:WxoYUrd9ZF7yvBohEdQfANEhD59a7eq6DNOkbpLP7Lw=
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
Expand Down
Empty file added out.txt
Empty file.

0 comments on commit e964202

Please sign in to comment.