campaigner/cmd/root.go

65 lines
1.2 KiB
Go
Raw Normal View History

2020-02-28 23:54:14 +01:00
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
2020-04-29 19:52:15 +02:00
"git.ctrlz.es/mgdelacroix/campaigner/app"
2020-02-28 23:54:14 +01:00
)
2020-04-29 19:52:15 +02:00
func withApp(f func(*app.App, *cobra.Command, []string)) func(*cobra.Command, []string) {
return func(cmd *cobra.Command, args []string) {
2020-09-24 13:34:25 +02:00
campaignPath, _ := cmd.Flags().GetString("campaign")
a, err := app.NewApp(campaignPath)
2020-04-30 16:54:04 +02:00
if err != nil {
fmt.Fprintln(os.Stderr, "ERROR: "+err.Error())
os.Exit(1)
}
2020-04-29 19:52:15 +02:00
f(a, cmd, args)
}
}
func withAppE(f func(*app.App, *cobra.Command, []string) error) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
2020-04-30 16:54:04 +02:00
a, err := app.NewApp("./campaign.json")
if err != nil {
fmt.Fprintln(os.Stderr, "ERROR: "+err.Error())
os.Exit(1)
}
2020-04-29 19:52:15 +02:00
return f(a, cmd, args)
}
}
2020-02-29 00:02:56 +01:00
func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "campaigner",
Short: "Create and manage Open Source campaigns",
}
2020-09-24 13:34:25 +02:00
cmd.PersistentFlags().String("campaign", "campaign.json", "the path to the campaign file")
2020-02-29 00:02:56 +01:00
cmd.AddCommand(
2020-02-29 00:59:54 +01:00
AddCmd(),
2020-04-27 12:22:15 +02:00
// FilterCmd(),
2020-02-29 00:49:55 +01:00
InitCmd(),
2020-03-06 19:54:52 +01:00
StatusCmd(),
2020-03-04 22:22:16 +01:00
PublishCmd(),
2020-04-30 08:13:31 +02:00
PullCmd(),
2020-03-04 22:26:04 +01:00
SyncCmd(),
2020-09-24 14:02:04 +02:00
ReportCmd(),
2020-02-29 00:02:56 +01:00
)
2020-02-29 00:23:26 +01:00
2020-02-29 00:02:56 +01:00
return cmd
2020-02-28 23:54:14 +01:00
}
func Execute() {
2020-02-29 00:02:56 +01:00
if err := RootCmd().Execute(); err != nil {
2020-02-28 23:54:14 +01:00
fmt.Fprintln(os.Stderr, err)
}
}