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