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 committed 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
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
@@ -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
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.