Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(addons-info): Add addons-info command and documentation #689

Merged
merged 9 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

* feat(addons-info): add command `addons-info` to display information of an add-on [#689](https://github.com/Scalingo/cli/pull/689)
* build(deps): bump github.com/Scalingo/go-utils/errors from 1.0.0 to 1.1.0 [#687](https://github.com/Scalingo/cli/pull/687)
* build(deps): bump github.com/Scalingo/go-utils/retry from 1.0.0 to 1.1.0 [#688](https://github.com/Scalingo/cli/pull/688)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ COMMANDS:
addons-add Provision an add-on for your application
addons-remove Remove an existing addon from your app
addons-upgrade Upgrade or downgrade an add-on attached to your app
addons-info Display information about an add-on attached to your app
backups-config Configure the periodic backups of a database
backups List backups for an addon
backups-create Ask for a new backup
Expand Down
51 changes: 51 additions & 0 deletions addons/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package addons

import (
"fmt"
"os"
"strings"

"github.com/olekukonko/tablewriter"
"gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/db"
)

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

addonInfo, err := c.AddonShow(app, addon)
if err != nil {
return errgo.Notef(err, "fail to get addon information")
}

dbInfo, err := db.Show(app, addon)
if err != nil {
return errgo.Notef(err, "fail to get database information")
}

forceSsl, internetAccess := "disabled", "disabled"
for i := range dbInfo.Features {
if dbInfo.Features[i]["name"] == "force-ssl" {
forceSsl = strings.ToLower(dbInfo.Features[i]["status"])
} else if dbInfo.Features[i]["name"] == "publicly-available" {
internetAccess = strings.ToLower(dbInfo.Features[i]["status"])
}
}

t := tablewriter.NewWriter(os.Stdout)
t.Append([]string{"Database Type", fmt.Sprintf("%v", dbInfo.TypeName)})
t.Append([]string{"Version", fmt.Sprintf("%v", dbInfo.ReadableVersion)})
t.Append([]string{"Status", fmt.Sprintf("%v", addonInfo.Status)})
t.Append([]string{"Plan", fmt.Sprintf("%v", addonInfo.Plan.Name)})
t.Append([]string{"Force TLS", forceSsl})
t.Append([]string{"Internet Accessibility", internetAccess})

t.Render()

return nil
}
31 changes: 30 additions & 1 deletion cmd/addons.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cmd

import (
"github.com/urfave/cli"

"github.com/Scalingo/cli/addons"
"github.com/Scalingo/cli/appdetect"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/urfave/cli"
)

var (
Expand Down Expand Up @@ -116,4 +117,32 @@ var (
autocomplete.AddonsUpgradeAutoComplete(c)
},
}
AddonsInfoCommand = cli.Command{
Name: "addons-info",
Category: "Addons",
Usage: "Display information about an add-on attached to your app",
Flags: []cli.Flag{appFlag, addonFlag},
Description: ` Display information about an add-on attached to your app:
$ scalingo --app my-app addons-info --addon <addon-id>

# See also 'addons' and 'addons-upgrade'
`,
Action: func(c *cli.Context) {
if len(c.Args()) != 0 {
cli.ShowCommandHelp(c, "addons-info")
return
}

currentApp := appdetect.CurrentApp(c)
currentAddon := addonName(c)

err := addons.Info(currentApp, currentAddon)
if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "addons-info")
},
}
)
1 change: 1 addition & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ var (
AddonsAddCommand,
AddonsRemoveCommand,
AddonsUpgradeCommand,
AddonsInfoCommand,

// Integration Link
integrationLinkShowCommand,
Expand Down