Skip to content

Commit

Permalink
Merge pull request #436 from Scalingo/fix/429/stack_improvements
Browse files Browse the repository at this point in the history
Various improvements to stacks-set
  • Loading branch information
Soulou authored Jul 3, 2019
2 parents e3d4c05 + b03440d commit e99cd98
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/autocomplete/collaborators_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"sync"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/go-scalingo/debug"
"github.com/Scalingo/go-scalingo"
"github.com/Scalingo/go-scalingo/debug"
"github.com/urfave/cli"
"gopkg.in/errgo.v1"
)
Expand Down
28 changes: 28 additions & 0 deletions cmd/autocomplete/stacks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package autocomplete

import (
"fmt"

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

func StacksSetAutoComplete(c *cli.Context) error {
client, err := config.ScalingoClient()
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
}

stacks, err := client.StacksList()
if err != nil {
return nil
}

for _, stack := range stacks {
fmt.Println(stack.ID)
fmt.Println(stack.Name)
}

return nil
}
29 changes: 17 additions & 12 deletions cmd/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/Scalingo/cli/appdetect"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/stacks"
"github.com/urfave/cli"
)
Expand All @@ -11,8 +12,10 @@ var (
Name: "stacks",
Category: "Runtime Stacks",
Usage: "List the available runtime stacks",
Description: ` List all the available runtime stacks for your apps:
$ scalingo stacks
Description: `List all the available runtime stacks for your apps:
Example:
scalingo stacks
# See also 'stacks-set'
`,
Expand All @@ -29,27 +32,29 @@ var (
Name: "stacks-set",
Category: "Runtime Stacks",
Usage: "Set the runtime stack of an app",
Flags: []cli.Flag{appFlag, cli.StringFlag{
Name: "stack",
Usage: "Stack to use", Value: "<stack id or name>"},
},
Description: ` Set the runtime stack of an app (deployment cache will be reseted):
$ scalingo -a my-app stacks-set
Flags: []cli.Flag{appFlag},
Description: `Set the runtime stack of an app (deployment cache will be reseted):
Example:
scalingo --app my-app stacks-set scalingo-18
# See also 'stacks'
`,
Before: AuthenticateHook,
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
var err error
if len(c.Args()) == 0 {
err = stacks.Set(currentApp, c.String("stack"))
} else {
if len(c.Args()) != 1 {
cli.ShowCommandHelp(c, "stacks-set")
return
}

err := stacks.Set(currentApp, c.Args()[0])
if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.StacksSetAutoComplete(c)
},
}
)

0 comments on commit e99cd98

Please sign in to comment.