-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rosco Nap
authored and
Rosco Nap
committed
Dec 4, 2018
1 parent
7b1e786
commit 7c5f87b
Showing
3 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import ( | |
"fmt" | ||
"os" | ||
|
||
"github.com/cloudrkt/statuspage-cli/email" | ||
"git.proserve.nl/statuspage/email" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
@@ -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] | ||
|
||
|
@@ -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) | ||
}, | ||
} | ||
|
||
|
@@ -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) | ||
}, | ||
} | ||
|
||
|
@@ -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) | ||
} |