Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
binary: shipyard-linux-amd64
- os: macos-latest
binary: shipyard-darwin-arm64
- os: macos-13
binary: shipyard-darwin-amd64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand Down
11 changes: 2 additions & 9 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ import (
// APIToken tries to read a token for the Shipyard API
// from the environment variable or loaded config (in that order).
func APIToken() (string, error) {
// Check if we're in test mode (same detection as spinner)
if buildURL := os.Getenv("SHIPYARD_BUILD_URL"); buildURL == "http://localhost:8000" {
return "test-token-from-test-mode", nil
}

// Check environment variable first
if token := os.Getenv("SHIPYARD_API_TOKEN"); token != "" {
return token, nil
}

// Fall back to viper config

token := viper.GetString("api_token")
if token == "" {
return "", errors.New("missing token")
return "", errors.New("token is missing, set the 'SHIPYARD_API_TOKEN' environment variable or 'api_token' config value")
}
return token, nil
}
59 changes: 56 additions & 3 deletions commands/env/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strconv"

"github.com/fatih/color"
"github.com/shipyard/shipyard-cli/pkg/client"
"github.com/shipyard/shipyard-cli/pkg/completion"
"github.com/shipyard/shipyard-cli/pkg/display"
Expand Down Expand Up @@ -129,7 +130,15 @@ func handleGetAllEnvironments(c client.Client) error {
params["org"] = org
}

// Start spinner
spinner := display.NewSpinner("Fetching info please standby...")
spinner.Start()

body, err := c.Requester.Do(http.MethodGet, uri.CreateResourceURI("", "environment", "", "", params), "application/json", nil)

// Stop spinner immediately after API call
spinner.Stop()

if err != nil {
return err
}
Expand All @@ -148,15 +157,50 @@ func handleGetAllEnvironments(c client.Client) error {
return nil
}

// Detect duplicate UUIDs and generate colors
duplicateUUIDs := display.GetDuplicateUUIDs(r.Data)
duplicateColors := display.GenerateDuplicateColors(duplicateUUIDs)

var data [][]string
for i := range r.Data {
i := i
data = append(data, display.FormattedEnvironment(&r.Data[i])...)
data = append(data, display.FormattedEnvironmentWithDuplicateColors(&r.Data[i], duplicateColors)...)
}
columns := []string{"App", "UUID", "Ready", "Repo", "PR#", "URL"}
display.RenderTable(os.Stdout, columns, data)
if r.Links.Next != "" {
display.Println(fmt.Sprintf("Table is truncated, fetch the next page %d.", r.Links.NextPage()))
nextPage := r.Links.NextPage()
cmd := " shipyard get environments --page " + strconv.Itoa(nextPage)

// Add current flags to the command
if name := viper.GetString("name"); name != "" {
cmd += " --name \"" + name + "\""
}
if orgName := viper.GetString("org-name"); orgName != "" {
cmd += " --org-name \"" + orgName + "\""
}
if repoName := viper.GetString("repo-name"); repoName != "" {
cmd += " --repo-name \"" + repoName + "\""
}
if branch := viper.GetString("branch"); branch != "" {
cmd += " --branch \"" + branch + "\""
}
if pullRequestNumber := viper.GetString("pull-request-number"); pullRequestNumber != "" {
cmd += " --pull-request-number \"" + pullRequestNumber + "\""
}
if deleted := viper.GetBool("deleted"); deleted {
cmd += " --deleted"
}
if pageSize := viper.GetInt("page-size"); pageSize != 0 && pageSize != 20 {
cmd += " --page-size " + strconv.Itoa(pageSize)
}
if viper.GetBool("json") {
cmd += " --json"
}
cmd += " "

styledCmd := color.New(color.FgHiWhite, color.BgBlue).Sprint(cmd)
display.Println(fmt.Sprintf("Table is truncated, fetch the next page %d. %s", nextPage, styledCmd))
}
return nil
}
Expand All @@ -167,7 +211,15 @@ func handleGetEnvironmentByID(c client.Client, id string) error {
params["org"] = org
}

// Start spinner
spinner := display.NewSpinner("Fetching info please standby...")
spinner.Start()

body, err := c.Requester.Do(http.MethodGet, uri.CreateResourceURI("", "environment", id, "", params), "application/json", nil)

// Stop spinner immediately after API call
spinner.Stop()

if err != nil {
return err
}
Expand All @@ -182,7 +234,8 @@ func handleGetEnvironmentByID(c client.Client, id string) error {
return err
}

data := display.FormattedEnvironment(&r.Data)
var data [][]string
data = append(data, display.FormattedEnvironment(&r.Data)...)
columns := []string{"App", "UUID", "Ready", "Repo", "PR#", "URL"}
display.RenderTable(os.Stdout, columns, data)
return nil
Expand Down
15 changes: 12 additions & 3 deletions commands/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ func NewGetServicesCmd(c client.Client) *cobra.Command {

func handleGetServicesCmd(c client.Client) error {
id := viper.GetString("env")

// Start spinner
spinner := display.NewSpinner("Fetching info please standby...")
spinner.Start()

svcs, err := c.AllServices(id)

// Stop spinner immediately after API call
spinner.Stop()

if err != nil {
return fmt.Errorf("failed to get services for environment %s: %w", id, err)
}
Expand All @@ -47,13 +56,13 @@ func handleGetServicesCmd(c client.Client) error {
}

data = append(data, []string{
s.Name,
display.FormatColoredAppName(s.Name),
ports,
s.URL,
display.FormatClickableURL(s.URL),
})
}

columns := []string{"Name", "Ports", "URL"}
columns := []string{"Services", "Ports", "URL"}
display.RenderTable(os.Stdout, columns, data)
return nil
}
18 changes: 17 additions & 1 deletion commands/volumes/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strconv"

"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down Expand Up @@ -83,7 +84,22 @@ func handleGetVolumeSnapshotsCmd(c client.Client) error {
columns := []string{"From", "Sequence", "Status", "Type"}
display.RenderTable(os.Stdout, columns, data)
if resp.Links.Next != "" {
display.Println(fmt.Sprintf("Table is truncated, fetch the next page %d.", resp.Links.NextPage()))
nextPage := resp.Links.NextPage()
cmd := " shipyard get volumes snapshots --page " + strconv.Itoa(nextPage) + " "

// Add current flags to the command
if env := viper.GetString("env"); env != "" {
cmd += " --env \"" + env + "\""
}
if pageSize := viper.GetInt("page-size"); pageSize != 0 && pageSize != 20 {
cmd += " --page-size " + strconv.Itoa(pageSize)
}
if viper.GetBool("json") {
cmd += " --json"
}

styledCmd := color.New(color.FgHiWhite, color.BgBlue).Sprint(cmd)
display.Println(fmt.Sprintf("Table is truncated, fetch the next page %d. %s", nextPage, styledCmd))
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/dsnet/compress v0.0.1
github.com/fatih/color v1.18.0
github.com/google/go-cmp v0.7.0
github.com/jedib0t/go-pretty/v6 v6.6.8
github.com/mattn/go-isatty v0.0.20
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/spf13/cobra v1.10.1
github.com/spf13/viper v1.21.0
Expand Down Expand Up @@ -48,7 +48,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
Expand All @@ -59,8 +59,8 @@ require (
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.6.8 h1:JnnzQeRz2bACBobIaa/r+nqjvws4yEhcmaZ4n1QzsEc=
github.com/jedib0t/go-pretty/v6 v6.6.8/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand All @@ -115,7 +117,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
Expand All @@ -131,8 +132,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo/v2 v2.1.6 h1:Fx2POJZfKRQcM1pH49qSZiYeu319wji004qX+GDovrU=
github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q=
Expand All @@ -146,8 +145,9 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down Expand Up @@ -222,10 +222,10 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
Loading
Loading