diff --git a/CHANGELOG.md b/CHANGELOG.md index 22f9d7706..fe1f9316e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Gopkg.lock b/Gopkg.lock index 55cf47d21..ac34751b9 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -10,7 +10,7 @@ revision = "8eb48cc6f27eafda8e3a9627edba494a1d229a01" [[projects]] - digest = "1:49225d9b4bc7c37a606e9f18c963ddd79ba55541ee696495e415154b2e77ed74" + digest = "1:81fa6c05d1c851dd921bdba158a1243da588f71fe0385fd5de496fcdd284d4b6" name = "github.com/Scalingo/go-scalingo" packages = [ ".", @@ -21,8 +21,8 @@ "io", ] pruneopts = "NUT" - revision = "b86a840520ff122c737acf56feeeb8fb072525dc" - version = "v2.4.4" + revision = "7ac6c591f584f85601dad484f2bcc34543ab9942" + version = "v2.4.5" [[projects]] branch = "master" diff --git a/apps/info.go b/apps/info.go new file mode 100644 index 000000000..30e4f061e --- /dev/null +++ b/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") +} diff --git a/cmd/apps.go b/cmd/apps.go index ca4e0483c..4e2806b4c 100644 --- a/cmd/apps.go +++ b/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" @@ -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") + }, + } ) diff --git a/cmd/commands.go b/cmd/commands.go index 611e7256f..1eab3681f 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -55,7 +55,8 @@ var ( appsCommand, CreateCommand, DestroyCommand, - RenameCommand, + renameCommand, + appsInfoCommand, // Apps Actions LogsCommand, diff --git a/cmd/domains.go b/cmd/domains.go index e06e6e966..345cfa5ff 100644 --- a/cmd/domains.go +++ b/cmd/domains.go @@ -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'`, diff --git a/cmd/rename.go b/cmd/rename.go index d1077de9a..119c56bb9 100644 --- a/cmd/rename.go +++ b/cmd/rename.go @@ -10,7 +10,7 @@ import ( ) var ( - RenameCommand = cli.Command{ + renameCommand = cli.Command{ Name: "rename", Category: "App Management", Flags: []cli.Flag{ diff --git a/vendor/github.com/Scalingo/go-scalingo/apps.go b/vendor/github.com/Scalingo/go-scalingo/apps.go index f6c54f9ef..ca63b4b69 100644 --- a/vendor/github.com/Scalingo/go-scalingo/apps.go +++ b/vendor/github.com/Scalingo/go-scalingo/apps.go @@ -101,6 +101,10 @@ type App struct { CreatedAt *time.Time `json:"created_at"` UpdatedAt *time.Time `json:"update_at"` Links *AppLinks `json:"links"` + StackID string `json:"stack_id"` + StickySession bool `json:"sticky_session"` + ForceHTTPS bool `json:"force_https"` + RouterLogs bool `json:"router_logs"` } func (app App) String() string {