Skip to content

Commit

Permalink
Add the apps-info command
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneM committed Jul 3, 2019
1 parent e99cd98 commit ce63ba5
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

### To be Released

* Add the `apps-info` command [#438](https://github.com/Scalingo/cli/pull/438)
* Display request ID in debug logs [#435](https://github.com/Scalingo/cli/pull/435)
* Add `git-setup` and `git-show` commands [#431](https://github.com/Scalingo/cli/pull/431)
* Remove dependency to an old Git lib for a more battle tested one [#434](https://github.com/Scalingo/cli/pull/434)
Expand Down
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions apps/info.go
@@ -0,0 +1,55 @@
package apps

import (
"fmt"
"os"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/go-scalingo"
"github.com/Scalingo/go-scalingo/debug"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
"gopkg.in/errgo.v1"
)

func Info(appName string) error {
c, err := config.ScalingoClient()
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
}

app, err := c.AppsShow(appName)
if err != nil {
return errgo.Notef(err, "fail to get the application information")
}

stackName, err := getStackName(c, app.StackID)
if err != nil {
debug.Println("Failed to get the stack name from its ID:", err)
stackName = app.StackID
}

t := tablewriter.NewWriter(os.Stdout)
t.SetHeader([]string{"Settings", "Value"})
t.Append([]string{"Force HTTPS", fmt.Sprintf("%v", app.ForceHTTPS)})
t.Append([]string{"Sticky Session", fmt.Sprintf("%v", app.StickySession)})
t.Append([]string{"Stack", stackName})
t.Append([]string{"Status", fmt.Sprintf("%v", app.Status)})
t.Render()

return nil
}

func getStackName(c *scalingo.Client, stackID string) (string, error) {
stacks, err := c.StacksList()
if err != nil {
return "", err
}

for _, stack := range stacks {
if stack.ID == stackID {
return stack.Name, nil
}
}
return "", errors.New("unknown stack")
}
23 changes: 23 additions & 0 deletions cmd/apps.go
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/Scalingo/cli/appdetect"
"github.com/Scalingo/cli/apps"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/urfave/cli"
Expand All @@ -22,4 +23,26 @@ var (
autocomplete.CmdFlagsAutoComplete(c, "apps")
},
}

appsInfoCommand = cli.Command{
Name: "apps-info",
Category: "App Management",
Flags: []cli.Flag{appFlag},
Usage: "Display the application information",
Description: `Display various application information such as the force HTTPS status, the stack configured, sticky sessions, etc.
Example:
scalingo apps-info --app my-app
`,
Before: AuthenticateHook,
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
if err := apps.Info(currentApp); err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "apps-info")
},
}
)
3 changes: 2 additions & 1 deletion cmd/commands.go
Expand Up @@ -55,7 +55,8 @@ var (
appsCommand,
CreateCommand,
DestroyCommand,
RenameCommand,
renameCommand,
appsInfoCommand,

// Apps Actions
LogsCommand,
Expand Down
2 changes: 1 addition & 1 deletion cmd/domains.go
Expand Up @@ -15,7 +15,7 @@ var (
Usage: "List the domains of an application",
Description: `List all the custom domains of an application:
$ scalingo -a myapp domains
$ scalingo --app my-app domains
# See also commands 'domains-add' and 'domains-remove'`,

Expand Down
2 changes: 1 addition & 1 deletion cmd/rename.go
Expand Up @@ -10,7 +10,7 @@ import (
)

var (
RenameCommand = cli.Command{
renameCommand = cli.Command{
Name: "rename",
Category: "App Management",
Flags: []cli.Flag{
Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/Scalingo/go-scalingo/apps.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ce63ba5

Please sign in to comment.