From 21c18b30955bf588294b54a2fe97f0a27db25f0c Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 16 Apr 2020 10:05:01 +0200 Subject: [PATCH] Removes --project flag Removed the need to use --project as its value is now inferred from --epic. This commit adds an example of use to the `init` command too --- cmd/init.go | 13 ++++++++++--- cmd/standalone.go | 5 ++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index 038d676..d3778d8 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -1,6 +1,8 @@ package cmd import ( + "strings" + "git.ctrlz.es/mgdelacroix/campaigner/campaign" "git.ctrlz.es/mgdelacroix/campaigner/model" @@ -11,14 +13,18 @@ func InitCmd() *cobra.Command { cmd := &cobra.Command{ Use: "init", Short: "Creates a new campaign in the current directory", + Example: ` campaigner init \ + --url http://my-jira-instance.com \ + --epic ASD-27 \ + --issue-type Story \ + --summary 'Refactor {{.function}} to inject the configuration service' \ + --template ./refactor-config.tmpl`, Args: cobra.NoArgs, Run: initCmdF, } cmd.Flags().StringP("url", "u", "", "The jira server URL") _ = cmd.MarkFlagRequired("url") - cmd.Flags().StringP("project", "p", "", "The jira project key to associate the tickets with") - _ = cmd.MarkFlagRequired("project") cmd.Flags().StringP("epic", "e", "", "The epic id to associate this campaign with") _ = cmd.MarkFlagRequired("epic") cmd.Flags().StringP("summary", "s", "", "The summary of the tickets") @@ -32,12 +38,13 @@ func InitCmd() *cobra.Command { func initCmdF(cmd *cobra.Command, _ []string) { url, _ := cmd.Flags().GetString("url") - project, _ := cmd.Flags().GetString("project") epic, _ := cmd.Flags().GetString("epic") summary, _ := cmd.Flags().GetString("summary") template, _ := cmd.Flags().GetString("template") issueType, _ := cmd.Flags().GetString("issue-type") + project := strings.Split(epic, "-")[0] + cmp := &model.Campaign{ Url: url, Project: project, diff --git a/cmd/standalone.go b/cmd/standalone.go index 3da854b..07993d1 100644 --- a/cmd/standalone.go +++ b/cmd/standalone.go @@ -37,8 +37,6 @@ func CreateJiraTicketStandaloneCmd() *cobra.Command { _ = cmd.MarkFlagRequired("url") cmd.Flags().String("epic", "", "The jira epic id to associate the ticket with") _ = cmd.MarkFlagRequired("epic") - cmd.Flags().StringP("project", "p", "", "The jira project key to associate the tickets with") - _ = cmd.MarkFlagRequired("project") cmd.Flags().String("summary", "", "The summary of the ticket") _ = cmd.MarkFlagRequired("summary") cmd.Flags().String("template", "", "The template to render the description of the ticket") @@ -82,7 +80,6 @@ func getVarMap(vars []string) (map[string]interface{}, error) { func createJiraTicketStandaloneCmdF(cmd *cobra.Command, _ []string) error { url, _ := cmd.Flags().GetString("url") epic, _ := cmd.Flags().GetString("epic") - project, _ := cmd.Flags().GetString("project") username, _ := cmd.Flags().GetString("username") token, _ := cmd.Flags().GetString("token") summary, _ := cmd.Flags().GetString("summary") @@ -90,6 +87,8 @@ func createJiraTicketStandaloneCmdF(cmd *cobra.Command, _ []string) error { vars, _ := cmd.Flags().GetStringSlice("vars") dryRun, _ := cmd.Flags().GetBool("dry-run") + project := strings.Split(epic, "-")[0] + if username == "" || token == "" { cfg, err := config.ReadConfig() if err != nil {