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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var (
RenameCommand = cli.Command{
renameCommand = cli.Command{
Name: "rename",
Category: "App Management",
Flags: []cli.Flag{
Expand Down

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.