Add template support for issue creation (bd-164b)
- Built-in templates: epic, bug, feature (embedded in binary) - Custom templates in .beads/templates/ (override built-ins) - Commands: bd template list/show/create - Flag: bd create --from-template <name> "Title" - Template fields: description, type, priority, labels, design, acceptance - Security: sanitize template names to prevent path traversal - Flag precedence: explicit flags override template defaults - Tests: template loading, security, flag precedence - Docs: commands/template.md and README.md updated Closes bd-164b Amp-Thread-ID: https://ampcode.com/threads/T-118fe54f-b112-4f99-a3d9-b7df53fb7284 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -19,6 +19,7 @@ var createCmd = &cobra.Command{
|
||||
Args: cobra.MinimumNArgs(0), // Changed to allow no args when using -f
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
file, _ := cmd.Flags().GetString("file")
|
||||
fromTemplate, _ := cmd.Flags().GetString("from-template")
|
||||
|
||||
// If file flag is provided, parse markdown and create multiple issues
|
||||
if file != "" {
|
||||
@@ -52,13 +53,51 @@ var createCmd = &cobra.Command{
|
||||
fmt.Fprintf(os.Stderr, "Error: title required (or use --file to create from markdown)\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Load template if specified
|
||||
var tmpl *Template
|
||||
if fromTemplate != "" {
|
||||
var err error
|
||||
tmpl, err = loadTemplate(fromTemplate)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Get field values, preferring explicit flags over template defaults
|
||||
description, _ := cmd.Flags().GetString("description")
|
||||
if description == "" && tmpl != nil {
|
||||
description = tmpl.Description
|
||||
}
|
||||
|
||||
design, _ := cmd.Flags().GetString("design")
|
||||
if design == "" && tmpl != nil {
|
||||
design = tmpl.Design
|
||||
}
|
||||
|
||||
acceptance, _ := cmd.Flags().GetString("acceptance")
|
||||
if acceptance == "" && tmpl != nil {
|
||||
acceptance = tmpl.AcceptanceCriteria
|
||||
}
|
||||
priority, _ := cmd.Flags().GetInt("priority")
|
||||
if cmd.Flags().Changed("priority") == false && tmpl != nil {
|
||||
priority = tmpl.Priority
|
||||
}
|
||||
|
||||
issueType, _ := cmd.Flags().GetString("type")
|
||||
if !cmd.Flags().Changed("type") && tmpl != nil && tmpl.Type != "" {
|
||||
// Flag not explicitly set and template has a type, use template
|
||||
issueType = tmpl.Type
|
||||
}
|
||||
|
||||
assignee, _ := cmd.Flags().GetString("assignee")
|
||||
|
||||
labels, _ := cmd.Flags().GetStringSlice("labels")
|
||||
if len(labels) == 0 && tmpl != nil && len(tmpl.Labels) > 0 {
|
||||
labels = tmpl.Labels
|
||||
}
|
||||
|
||||
explicitID, _ := cmd.Flags().GetString("id")
|
||||
parentID, _ := cmd.Flags().GetString("parent")
|
||||
externalRef, _ := cmd.Flags().GetString("external-ref")
|
||||
@@ -259,6 +298,7 @@ var createCmd = &cobra.Command{
|
||||
|
||||
func init() {
|
||||
createCmd.Flags().StringP("file", "f", "", "Create multiple issues from markdown file")
|
||||
createCmd.Flags().String("from-template", "", "Create issue from template (e.g., 'epic', 'bug', 'feature')")
|
||||
createCmd.Flags().String("title", "", "Issue title (alternative to positional argument)")
|
||||
createCmd.Flags().StringP("description", "d", "", "Issue description")
|
||||
createCmd.Flags().String("design", "", "Design notes")
|
||||
|
||||
Reference in New Issue
Block a user