campaigner/cmd/init.go

50 lines
1.4 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
}
cmd.Flags().StringP("url", "u", "", "The jira server URL")
2020-03-05 17:38:53 +01:00
_ = cmd.MarkFlagRequired("url")
cmd.Flags().StringP("project", "p", "", "The jira project key to associate the tickets with")
2020-03-04 23:59:23 +01:00
_ = cmd.MarkFlagRequired("project")
cmd.Flags().StringP("epic", "e", "", "The epic id to associate this campaign with")
2020-02-29 17:45:53 +01:00
_ = cmd.MarkFlagRequired("epic")
cmd.Flags().StringP("summary", "s", "", "The summary of the tickets")
2020-02-29 17:48:53 +01:00
_ = cmd.MarkFlagRequired("summary")
cmd.Flags().StringP("template", "t", "", "The template path for the description of the tickets")
_ = cmd.MarkFlagRequired("template")
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-05 17:38:53 +01:00
url, _ := cmd.Flags().GetString("url")
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")
template, _ := cmd.Flags().GetString("template")
2020-03-05 17:38:53 +01:00
cmp := &model.Campaign{
Url: url,
Project: project,
Epic: epic,
Summary: summary,
Template: template,
2020-03-05 17:38:53 +01:00
}
if err := campaign.Save(cmp); err != nil {
2020-02-29 13:33:03 +01:00
ErrorAndExit(cmd, err)
}
2020-02-29 00:49:55 +01:00
}