Skip to content

Commit

Permalink
Added list and resend options
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosco Nap authored and Rosco Nap committed Dec 4, 2018
1 parent 7b1e786 commit 7c5f87b
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# statuspage-cli

Statuspage.io CLI tool
Statuspage.io CLI tool

## Synopsis

This commandline tool interacts with the statuspage.io API.
This commandline tool interacts with the statuspage.io API.

*note: Beware, this is work in progress and without warranty! It might be broken.*

Expand Down
37 changes: 37 additions & 0 deletions cmd/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var componentCmd = &cobra.Command{
Use: "component",
Short: "Manipulate statuspage components",
}

var componentListCmd = &cobra.Command{
Use: "list",
Example: "statuspage component list",
Short: "list component",
Long: `Lists all components`,
Run: func(cmd *cobra.Command, args []string) {
components, err := app.Client.GetAllComponents()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

for _, component := range components {
fmt.Println(&component)
}

},
}

func init() {
RootCmd.AddCommand(componentCmd)
componentCmd.AddCommand(componentListCmd)
}
84 changes: 77 additions & 7 deletions cmd/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/cloudrkt/statuspage-cli/email"
"git.proserve.nl/statuspage/email"
"github.com/spf13/cobra"
)

Expand All @@ -13,14 +13,49 @@ var subscriberCmd = &cobra.Command{
Short: "Manipulate subscribers",
}

var subscriberListCmd = &cobra.Command{
Use: "list",
Example: "statuspage subscriber list [type]",
Short: "list subscribers",
Long: `Lists subscribers`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {

listAllSubscribers := func() {
subscribers, err := app.Client.GetAllSubscribers()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

for _, subscriber := range subscribers {
fmt.Println(&subscriber)
}
}

if len(args) < 1 {
listAllSubscribers()
} else {
switch args[0] {
case "sms": // TODO: Implement SMS subscriber list
fmt.Println("not implemented yet")
case "webhook": // TODO: Impelement webhook subscriber list
fmt.Println("not implemented yet")
default:
listAllSubscribers()
}
}
},
}

var subscriberCreateCmd = &cobra.Command{
Use: "create",
Example: "statuspage subscriber create [[email protected]]",
Short: "create a subscriber",
Long: `Create a subscriber through email adres. The subsciber *needs* to
Long: `Create a subscriber through email adres. The subsciber *needs* to
confirm the email from statuspage to receive notifications. The
subscriber is then added to all the components by default.`,
Args: cobra.ExactArgs(1),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
create := args[0]

Expand All @@ -40,8 +75,7 @@ var subscriberCreateCmd = &cobra.Command{
fmt.Println(err)
os.Exit(1)
}

fmt.Printf("Succesfully added: %v\n", create)
fmt.Printf("succesfully added: %v\n", create)
},
}

Expand Down Expand Up @@ -71,7 +105,7 @@ var subscriberDeleteCmd = &cobra.Command{
os.Exit(1)
}

fmt.Printf("Succesfully deleted: %v\n", *subscriber.Email)
fmt.Printf("succesfully deleted: %v\n", *subscriber.Email)
},
}

Expand All @@ -95,13 +129,49 @@ var subscriberSearchCmd = &cobra.Command{
os.Exit(1)
}

fmt.Println(subscriber.String())
fmt.Printf(subscriber.String())
},
}

var subscriberResendCmd = &cobra.Command{
Use: "resend",
Example: "statuspage subscriber resend [[email protected]]",
Short: "Resend conformation email",
Long: "Resend the conformation email to a subscriber",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
address := args[0]

if err := email.ValidateFormat(address); err != nil {
fmt.Println(err)
os.Exit(1)
}

subscriber, err := app.Client.SearchEmailSubscriber(address)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

if app.Debug {
fmt.Println("Found: ", subscriber)
}

_, err = app.Client.ResendConformationEmail(subscriber)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

fmt.Printf("succesfully resend conformation email to: %v\n", *subscriber.Email)
},
}

func init() {
RootCmd.AddCommand(subscriberCmd)
subscriberCmd.AddCommand(subscriberCreateCmd)
subscriberCmd.AddCommand(subscriberDeleteCmd)
subscriberCmd.AddCommand(subscriberListCmd)
subscriberCmd.AddCommand(subscriberSearchCmd)
subscriberCmd.AddCommand(subscriberResendCmd)
}

0 comments on commit 7c5f87b

Please sign in to comment.