Skip to content

Commit feeb585

Browse files
authored
feat: Accept multiple replace strings on clone (#811)
1 parent 0f83eaa commit feeb585

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

internal/cmd/issue/clone/clone.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,22 @@ func (cc *cloneCmd) getActualCreateParams(project string, issue *jira.Issue) *cr
209209
body = ""
210210
}
211211

212-
if cc.params.replace != "" {
213-
pieces := strings.Split(cc.params.replace, ":")
214-
if len(pieces) != 2 {
215-
fmt.Println()
216-
cmdutil.Fail("Invalid replace string, must be in format <find>:<replace>. Skipping replacement...")
217-
} else {
218-
from, to := pieces[0], pieces[1]
212+
if len(cc.params.replace) > 0 {
213+
for _, r := range cc.params.replace {
214+
pieces := strings.Split(r, ":")
215+
if len(pieces) != 2 {
216+
fmt.Println()
217+
cmdutil.Fail("Invalid replace string, must be in format <find>:<replace>. Skipping replacement...")
218+
} else {
219+
from, to := pieces[0], pieces[1]
219220

220-
cp.summary = strings.ReplaceAll(cp.summary, from, to)
221+
cp.summary = strings.ReplaceAll(cp.summary, from, to)
221222

222-
if isADF {
223-
body.(*adf.ADF).ReplaceAll(from, to)
224-
} else {
225-
body = strings.ReplaceAll(body.(string), from, to)
223+
if isADF {
224+
body.(*adf.ADF).ReplaceAll(from, to)
225+
} else {
226+
body = strings.ReplaceAll(body.(string), from, to)
227+
}
226228
}
227229
}
228230
}
@@ -238,7 +240,7 @@ type cloneParams struct {
238240
assignee string
239241
labels []string
240242
components []string
241-
replace string
243+
replace []string
242244
debug bool
243245
}
244246

@@ -261,7 +263,7 @@ func parseFlags(flags query.FlagParser) *cloneParams {
261263
components, err := flags.GetStringArray("component")
262264
cmdutil.ExitIfError(err)
263265

264-
replace, err := flags.GetString("replace")
266+
replace, err := flags.GetStringArray("replace")
265267
cmdutil.ExitIfError(err)
266268

267269
debug, err := flags.GetBool("debug")
@@ -288,6 +290,6 @@ func setFlags(cmd *cobra.Command) {
288290
cmd.Flags().StringP("assignee", "a", "", "Issue assignee (email or display name)")
289291
cmd.Flags().StringArrayP("label", "l", []string{}, "Issue labels")
290292
cmd.Flags().StringArrayP("component", "C", []string{}, "Issue components")
291-
cmd.Flags().StringP("replace", "H", "", "Replace strings in summary and body. Format <search>:<replace>, eg: \"find me:replace with me\"")
293+
cmd.Flags().StringArrayP("replace", "H", []string{}, "Replace strings in summary and body. Format <search>:<replace>, eg: \"find me:replace with me\"")
292294
cmd.Flags().Bool("web", false, "Open in web browser after successful cloning")
293295
}

0 commit comments

Comments
 (0)