Skip to content

Commit

Permalink
Merge branch 'master' into feature/update-go-scalingo
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulou committed Jul 14, 2017
2 parents 6f4d077 + 94982a4 commit 5a34929
Show file tree
Hide file tree
Showing 18 changed files with 991 additions and 19 deletions.
13 changes: 9 additions & 4 deletions Godeps/Godeps.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package autocomplete
import (
"fmt"

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

func NotificationsRemoveAutoComplete(c *cli.Context) error {
Expand Down
25 changes: 25 additions & 0 deletions cmd/autocomplete/notifiers_remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package autocomplete

import (
"fmt"

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

func NotifiersAutoComplete(c *cli.Context) error {
appName := CurrentAppCompletion(c)
if appName == "" {
return nil
}

client := config.ScalingoClient()
resources, err := client.NotifiersList(appName)
if err == nil {
for _, resource := range resources {
fmt.Println(resource.GetID())
}
}

return nil
}
10 changes: 10 additions & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ var (
NotificationsUpdateCommand,
NotificationsRemoveCommand,

// Notifiers
NotifiersListCommand,
NotifiersDetailsCommand,
NotifiersAddCommand,
NotifiersUpdateCommand,
NotifiersRemoveCommand,

// Notification platforms
NotificationPlatformListCommand,

// DB Access
DbTunnelCommand,
RedisConsoleCommand,
Expand Down
25 changes: 25 additions & 0 deletions cmd/notification_platforms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/notification_platforms"
"github.com/urfave/cli"
)

var (
NotificationPlatformListCommand = cli.Command{
Name: "notification-platforms",
Category: "Notifiers - Global",
Description: "List all notification platforms you can use with a notifier.",
Usage: "List all notification platforms",
Action: func(c *cli.Context) {
err := notification_platforms.List()
if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "platforms-list")
},
}
)
250 changes: 250 additions & 0 deletions cmd/notifiers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
package cmd

import (
"strings"

"github.com/Scalingo/cli/appdetect"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/notifiers"
scalingo "github.com/Scalingo/go-scalingo"
"github.com/urfave/cli"
)

var (
NotifiersListCommand = cli.Command{
Name: "notifiers",
Category: "Notifiers",
Usage: "List your notifiers",
Flags: []cli.Flag{appFlag},
Description: ` List all notifiers of your app:
$ scalingo -a myapp notifiers
# See also 'notifiers-add' and 'notifiers-remove'
`,
Before: AuthenticateHook,
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
var err error
if len(c.Args()) == 0 {
err = notifiers.List(currentApp)
} else {
cli.ShowCommandHelp(c, "notifiers")
}

if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "notifiers")
},
}

NotifiersDetailsCommand = cli.Command{
Name: "notifiers-details",
Category: "Notifiers",
Usage: "Show details of your notifiers",
Flags: []cli.Flag{appFlag},
Description: ` Show details of your notifiers:
$ scalingo -a myapp notifiers-details <ID>
# See also 'notifiers'
`,
Before: AuthenticateHook,
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
var err error
if len(c.Args()) == 1 {
err = notifiers.Details(currentApp, c.Args()[0])
} else {
cli.ShowCommandHelp(c, "notifiers-details")
}

if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "notifiers-details")
autocomplete.NotifiersAutoComplete(c)
},
}

NotifiersAddCommand = cli.Command{
Name: "notifiers-add",
Category: "Notifiers",
Flags: []cli.Flag{
appFlag,
cli.BoolFlag{Name: "enable, e", Usage: "Enable the notifier (default)"},
cli.BoolFlag{Name: "disable, d", Usage: "Disable the notifier"},
cli.StringFlag{Name: "platform, p", Value: "", Usage: "The notifier platform"},
cli.StringFlag{Name: "name, n", Value: "", Usage: "Name of the notifier"},
cli.BoolFlag{Name: "send-all-events, sa", Usage: "If true the notifier will send all events. Default: false"},
cli.StringFlag{Name: "events, ev", Value: "", Usage: "List of selected events. Default: []"},
cli.StringFlag{Name: "webhook-url, u", Value: "", Usage: "The webhook url to send notification (if applicable)"},
cli.StringFlag{Name: "phone", Value: "", Usage: "The phone number to send notifications (if applicable)"},
cli.StringFlag{Name: "email", Value: "", Usage: "The email to send notifications (if applicable)"},
},
Usage: "Add a notifier for your application",
Description: `Add a notifier for your application:
Examples
$ scalingo -a myapp notifiers-add \
--platform slack \
--name "My notifier" \
--webhook-url "https://hooks.slack.com/services/1234" \
--events "deployment stop_app"
$ scalingo -a myapp notifiers-add \
--platform webhook \
--name "My notifier" \
--webhook-url "https://custom-webhook.com" \
--send-all-events true
# Use 'platforms-list' to see all available platforms
# See also 'notifiers' and 'notifiers-remove'
`,
Before: AuthenticateHook,
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)

if c.String("platform") == "" {
cli.ShowCommandHelp(c, "notifiers-add")
}

var active bool
if c.IsSet("disable") {
active = false
} else {
active = true
}
sendAllEvents := c.Bool("send-all-events")

params := scalingo.NotifierParams{
Active: &active,
Name: c.String("name"),
SendAllEvents: &sendAllEvents,
SelectedEvents: strings.Split(c.String("events"), " "),

// Type data options
PhoneNumber: c.String("phone"),
Email: c.String("email"),
WebhookURL: c.String("webhook-url"),
}

err := notifiers.Provision(currentApp, c.String("platform"), params)
if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "notifiers-add")
},
}

NotifiersUpdateCommand = cli.Command{
Name: "notifiers-update",
Category: "Notifiers",
Flags: []cli.Flag{
appFlag,
cli.BoolFlag{Name: "enable, e", Usage: "Enable the notifier"},
cli.BoolFlag{Name: "disable, d", Usage: "Disable the notifier"},
cli.StringFlag{Name: "name, n", Value: "", Usage: "Name of the notifier"},
cli.BoolFlag{Name: "send-all-events, sa", Usage: "If true the notifier will send all events. Default: false"},
cli.StringFlag{Name: "events, ev", Value: "", Usage: "List of selected events. Default: []"},
cli.StringFlag{Name: "webhook-url, u", Value: "", Usage: "The webhook url to send notification (if applicable)"},
cli.StringFlag{Name: "phone", Value: "", Usage: "The phone number to send notifications (if applicable)"},
cli.StringFlag{Name: "email", Value: "", Usage: "The email to send notifications (if applicable)"},
},
Usage: "Update a notifier",
Description: `Update a notifier:
Examples
$ scalingo -a myapp notifiers-update --disable <ID>
$ scalingo -a myapp notifiers-update \
--name "My notifier" \
--webhook-url https://custom-webhook.com \
--send-all-events true \
<ID>
# See also 'notifiers' and 'notifiers-remove'
`,
Before: AuthenticateHook,
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
var err error

var active *bool
if c.IsSet("enable") {
tmpActive := true
active = &tmpActive
} else if c.IsSet("disable") {
tmpActive := false
active = &tmpActive
} else {
active = nil
}

var sendAllEvents *bool
if c.IsSet("send-all-events") {
tmpEvents := c.Bool("send-all-events")
sendAllEvents = &tmpEvents
} else {
sendAllEvents = nil
}

params := scalingo.NotifierParams{
Active: active,
Name: c.String("name"),
SendAllEvents: sendAllEvents,
SelectedEvents: strings.Split(c.String("events"), " "),

// Type data options
PhoneNumber: c.String("phone"),
Email: c.String("email"),
WebhookURL: c.String("webhook-url"),
}
if len(c.Args()) >= 1 {
err = notifiers.Update(currentApp, c.Args()[0], params)
} else {
cli.ShowCommandHelp(c, "notifiers-update")
}
if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "notifiers-update")
autocomplete.NotifiersAutoComplete(c)
},
}

NotifiersRemoveCommand = cli.Command{
Name: "notifiers-remove",
Category: "Notifiers",
Flags: []cli.Flag{appFlag},
Usage: "Remove an existing notifier from your app",
Description: `Remove an existing notifier from your app:
$ scalingo -a myapp notifier-remove <ID>
# See also 'notifiers' and 'notifiers-add'
`,
Before: AuthenticateHook,
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
var err error
if len(c.Args()) == 1 {
err = notifiers.Destroy(currentApp, c.Args()[0])
} else {
cli.ShowCommandHelp(c, "notifiers-remove")
}
if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "notifiers-remove")
autocomplete.NotifiersAutoComplete(c)
},
}
)
5 changes: 5 additions & 0 deletions io/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
boldBlueToken = "\033[1;34m"
yellowToken = "\033[33m"
greenToken = "\033[32m"
boldRedToken = "\033[1;31m"
grayToken = "\033[90m"
lightGrayToken = "\033[1;37m"
resetToken = "\033[0m"
Expand All @@ -20,6 +21,10 @@ func BoldBlue(s string) string {
return fmt.Sprintf("%s%s%s", boldBlueToken, s, resetToken)
}

func BoldRed(s string) string {
return fmt.Sprintf("%s%s%s", boldRedToken, s, resetToken)
}

func Green(s string) string {
return fmt.Sprintf("%s%s%s", greenToken, s, resetToken)
}
Expand Down
Loading

0 comments on commit 5a34929

Please sign in to comment.