Skip to content

Commit

Permalink
Merge pull request #567 from Scalingo/feature/554/add_log_drains_del_cmd
Browse files Browse the repository at this point in the history
Log drains: delete command
  • Loading branch information
EtienneM authored May 25, 2020
2 parents 363c29e + 2d8474b commit b50f48a
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Add log drains add command
[#561](https://github.com/Scalingo/cli/pull/561)
[go-scalingo #164](https://github.com/Scalingo/go-scalingo/pull/164)
* Add log drains delete command
[#567](https://github.com/Scalingo/cli/pull/567)
[go-scalingo #167](https://github.com/Scalingo/go-scalingo/pull/167)

### 1.17.0

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.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

[[constraint]]
name = "github.com/Scalingo/go-scalingo"
version = "^4"
version = "^4"

[[constraint]]
branch = "master"
Expand Down
9 changes: 5 additions & 4 deletions cmd/autocomplete/domains_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ func DomainsRemoveAutoComplete(c *cli.Context) error {
return errgo.Notef(err, "fail to get Scalingo client")
}
domains, err := client.DomainsList(appName)
if err == nil {
if err != nil {
return errgo.Notef(err, "fail to get domains list")
}

for _, domain := range domains {
fmt.Println(domain.Name)
}
for _, domain := range domains {
fmt.Println(domain.Name)
}

return nil
Expand Down
31 changes: 31 additions & 0 deletions cmd/autocomplete/log_drains_remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package autocomplete

import (
"fmt"

"github.com/Scalingo/cli/config"
"github.com/urfave/cli"
"gopkg.in/errgo.v1"
)

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

client, err := config.ScalingoClient()
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
}
drains, err := client.LogDrainsList(appName)
if err != nil {
return errgo.Notef(err, "fail to get log drains list")
}

for _, drain := range drains {
fmt.Println(drain.URL)
}

return nil
}
1 change: 1 addition & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ var (
// Log drains
logDrainsAddCommand,
logDrainsListCommand,
logDrainsRemoveCommand,

gitSetup,
gitShow,
Expand Down
34 changes: 32 additions & 2 deletions cmd/log_drains.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
$ scalingo --app my-app log-drains
# See also commands 'log-drains-add'`,
# See also commands 'log-drains-add', 'log-drains-remove'`,

Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
Expand Down Expand Up @@ -59,7 +59,7 @@ var (
$ scalingo --app my-app log-drains-add --type syslog --host custom.logstash.com --port 12345
$ scalingo --app my-app log-drains-add --type elk --url https://my-user:[email protected]
# See also commands 'log-drains'`,
# See also commands 'log-drains', 'log-drains-remove'`,

Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
Expand All @@ -80,4 +80,34 @@ var (
autocomplete.CmdFlagsAutoComplete(c, "log-drains")
},
}

logDrainsRemoveCommand = cli.Command{
Name: "log-drains-remove",
Category: "Log drains",
Flags: []cli.Flag{appFlag},
Usage: "Remove a log drain from an application",
Description: `Remove a log drain from an application:
$ scalingo --app my-app log-drains-remove syslog://custom.logstash.com:12345
# See also commands 'log-drains-add', 'log-drains'`,

Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
var err error
if len(c.Args()) == 1 {
err = log_drains.Remove(currentApp, c.Args()[0])
} else {
cli.ShowCommandHelp(c, "log-drains-remove")
}

if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "log-drains-remove")
autocomplete.LogDrainsRemoveAutoComplete(c)
},
}
)
22 changes: 22 additions & 0 deletions log_drains/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package log_drains

import (
"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"gopkg.in/errgo.v1"
)

func Remove(app string, URL string) error {
c, err := config.ScalingoClient()
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client to remove a log drain from the application")
}

err = c.LogDrainRemove(app, URL)
if err != nil {
return errgo.Notef(err, "fail to remove the log drain from the application")
}

io.Status("The log drain:", URL, "has been deleted")
return nil
}
24 changes: 24 additions & 0 deletions vendor/github.com/Scalingo/go-scalingo/log_drains.go

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

2 changes: 1 addition & 1 deletion vendor/github.com/Scalingo/go-scalingo/version.go

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

0 comments on commit b50f48a

Please sign in to comment.