campaigner/cmd/init.go

36 lines
1.1 KiB
Go
Raw Normal View History

2020-02-29 00:49:55 +01:00
package cmd
import (
2020-02-29 13:33:03 +01:00
"git.ctrlz.es/mgdelacroix/campaigner/campaign"
"git.ctrlz.es/mgdelacroix/campaigner/model"
2020-02-29 00:49:55 +01:00
"github.com/spf13/cobra"
)
func InitCmd() *cobra.Command {
2020-02-29 13:33:03 +01:00
cmd := &cobra.Command{
2020-02-29 00:49:55 +01:00
Use: "init",
Short: "Creates a new campaign in the current directory",
Args: cobra.NoArgs,
2020-02-29 13:33:03 +01:00
Run: initCmdF,
2020-02-29 00:49:55 +01:00
}
2020-03-04 23:59:23 +01:00
cmd.Flags().StringP("project", "p", "", "the jira project key to associate the tickets with")
_ = cmd.MarkFlagRequired("project")
2020-02-29 13:33:03 +01:00
cmd.Flags().StringP("epic", "e", "", "the epic id to associate this campaign with")
2020-02-29 17:45:53 +01:00
_ = cmd.MarkFlagRequired("epic")
2020-02-29 17:48:53 +01:00
cmd.Flags().StringP("summary", "s", "", "the summary of the tickets. Can contain the variables {{.Filename}}, {{.LineNo}} and {{.Text}}")
_ = cmd.MarkFlagRequired("summary")
2020-02-29 13:33:03 +01:00
return cmd
2020-02-29 00:49:55 +01:00
}
2020-02-29 13:33:03 +01:00
func initCmdF(cmd *cobra.Command, _ []string) {
2020-03-04 23:59:23 +01:00
project, _ := cmd.Flags().GetString("project")
2020-02-29 13:33:03 +01:00
epic, _ := cmd.Flags().GetString("epic")
2020-02-29 17:48:53 +01:00
summary, _ := cmd.Flags().GetString("summary")
2020-03-04 23:59:23 +01:00
if err := campaign.Save(&model.Campaign{Project: project, Epic: epic, Summary: summary}); err != nil {
2020-02-29 13:33:03 +01:00
ErrorAndExit(cmd, err)
}
2020-02-29 00:49:55 +01:00
}