Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scale): rename command ps to scale without arg #631

Merged
merged 2 commits into from
Mar 25, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Show the addon status on `scalingo addons` [#604](https://github.com/Scalingo/cli/pull/604)
* Add informative error in case of container type error when scaling an application
[602](https://github.com/Scalingo/cli/pull/602)
* `ps` command is renamed `scale` [#631](https://github.com/Scalingo/cli/pull/631)

### 1.19.3

Expand Down
58 changes: 58 additions & 0 deletions apps/containers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package apps

import (
"fmt"
"os"

"github.com/Scalingo/cli/config"
"github.com/olekukonko/tablewriter"
"gopkg.in/errgo.v1"
)

func ContainerTypes(app string) error {
c, err := config.ScalingoClient()
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client to list container types")
}

containerTypes, err := c.AppsPs(app)
if err != nil {
return errgo.Notef(err, "fail to list the application container types")
}

t := tablewriter.NewWriter(os.Stdout)
t.SetHeader([]string{"Name", "Amount", "Size", "Command"})

hasAutoscaler := false
autoscalers, err := c.AutoscalersList(app)
if err != nil {
return errgo.Notef(err, "fail to list the autoscalers")
}

for _, containerType := range containerTypes {
name := containerType.Name

for _, a := range autoscalers {
if a.ContainerType == containerType.Name {
hasAutoscaler = true
name += " (*)"
break
}
}

amount := fmt.Sprintf("%d", containerType.Amount)
if containerType.Command != "" {
t.Append([]string{name, amount, containerType.Size, "`" + containerType.Command + "`"})
} else {
t.Append([]string{name, amount, containerType.Size, "-"})
}
}

t.Render()

if hasAutoscaler {
fmt.Println(" (*) has an autoscaler defined")
}

return nil
}
58 changes: 0 additions & 58 deletions apps/ps.go

This file was deleted.

24 changes: 12 additions & 12 deletions apps/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ type ScaleRes struct {

func Scale(app string, sync bool, types []string) error {
var (
size string
containers []scalingo.ContainerType
modificator byte
err error
size string
containerTypes []scalingo.ContainerType
modificator byte
err error
)

c, err := config.ScalingoClient()
Expand All @@ -37,7 +37,7 @@ func Scale(app string, sync bool, types []string) error {
typesWithAutoscaler := []string{}
autoscalers, err := c.AutoscalersList(app)
if err != nil {
return errgo.NoteMask(err, "fail to list the autoscalers")
return errgo.Notef(err, "fail to list the autoscalers")
}

for _, t := range types {
Expand All @@ -56,12 +56,12 @@ func Scale(app string, sync bool, types []string) error {
if size != "" {
return errgo.Newf("%s is invalid, can't use relative modificator with size, change the size first", t)
}
if containers == nil {
containers, err = c.AppsPs(app)
if containerTypes == nil {
containerTypes, err = c.AppsPs(app)
if err != nil {
return errgo.Notef(err, "fail to get list of running containers")
}
debug.Println("get container list", containers)
debug.Println("get container list", containerTypes)
}
}

Expand All @@ -79,7 +79,7 @@ func Scale(app string, sync bool, types []string) error {

newContainerConfig := scalingo.ContainerType{Name: typeName, Size: size}
if modificator != 0 {
for _, container := range containers {
for _, container := range containerTypes {
if container.Name == typeName {
if modificator == '-' {
newContainerConfig.Amount = container.Amount - int(amount)
Expand Down Expand Up @@ -119,7 +119,7 @@ func Scale(app string, sync bool, types []string) error {
return formatContainerTypesError(c, app, reqestFailedError)
}

return errgo.Mask(err)
return errgo.Notef(err, "fail to scale the Scalingo application")
}
// If error is Payment Required and user tries to exceed its free trial
return utils.AskAndStopFreeTrial(c, func() error {
Expand All @@ -131,7 +131,7 @@ func Scale(app string, sync bool, types []string) error {
var scaleRes ScaleRes
err = json.NewDecoder(res.Body).Decode(&scaleRes)
if err != nil {
return errgo.Mask(err)
return errgo.Notef(err, "fail to decode API response to scale operation")
}

fmt.Printf("Your application is being scaled to:\n")
Expand All @@ -145,7 +145,7 @@ func Scale(app string, sync bool, types []string) error {

err = handleOperation(app, res)
if err != nil {
return errgo.Mask(err)
return errgo.Notef(err, "fail to handle the scale operation")
}

fmt.Println("Your application has been scaled.")
Expand Down
1 change: 0 additions & 1 deletion cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ var (
RunCommand,

// Apps Process Actions
psCommand,
scaleCommand,
RestartCommand,

Expand Down
35 changes: 0 additions & 35 deletions cmd/ps.go

This file was deleted.

8 changes: 4 additions & 4 deletions cmd/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ var (
cli.BoolFlag{Name: "synchronous, s", Usage: "Do the scaling synchronously", EnvVar: ""},
},
Usage: "Scale your application instantly",
Description: `Scale your application processes.
Description: `Scale your application processes. Without argument, this command lists the container types declared in your application.
Example
'scalingo --app my-app scale web:2 worker:1'
'scalingo --app my-app scale web:1 worker:0'
'scalingo --app my-app scale web:1:XL'
'scalingo --app my-app scale web:+1 worker:-1'
`,
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)

if len(c.Args()) == 0 {
err := cli.ShowCommandHelp(c, "scale")
err := apps.ContainerTypes(currentApp)
if err != nil {
errorQuit(err)
}
return
}

currentApp := appdetect.CurrentApp(c)

err := apps.Scale(currentApp, c.Bool("s"), c.Args())
if err != nil {
errorQuit(err)
Expand Down