#!/bin/bash # create-new-feature.sh - Spec-Driven Development Feature Initialization # Usage: create-new-feature.sh --json "feature-name" set -e # Parse arguments JSON_OUTPUT=false FEATURE_NAME="" while [[ $# -gt 0 ]]; do case $1 in --json) JSON_OUTPUT=true shift ;; *) FEATURE_NAME="$1" shift ;; esac done if [[ -z "$FEATURE_NAME" ]]; then echo "Error: Feature name is required" exit 1 fi # Clean feature name for branch BRANCH_NAME=$(echo "$FEATURE_NAME" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-\|-$//g' | tr '[:upper:]' '[:lower:]') SPEC_FILE="$(pwd)/.specify/specs/${BRANCH_NAME}.md" # Ensure we're in the right directory if [[ ! -d ".git" ]]; then echo "Error: Must be run from git repository root" exit 1 fi # Create specs directory if it doesn't exist mkdir -p .specify/specs # Create and checkout new branch git checkout -b "spec/${BRANCH_NAME}" 2>/dev/null || { echo "Branch spec/${BRANCH_NAME} may already exist, switching to it..." git checkout "spec/${BRANCH_NAME}" } # Create initial spec file cat > "$SPEC_FILE" << 'EOF' # Feature Specification Template This file will be populated with the complete specification. ## Status - **Created**: $(date +%Y-%m-%d) - **Branch**: spec/BRANCH_NAME - **Status**: Draft ## Placeholder This is a placeholder file created by create-new-feature.sh The complete specification will be written by the spec creation process. EOF # Output results if [[ "$JSON_OUTPUT" == "true" ]]; then cat << EOF { "status": "success", "branch_name": "spec/${BRANCH_NAME}", "spec_file": "$SPEC_FILE", "feature_name": "$FEATURE_NAME", "created_at": "$(date -Iseconds)" } EOF else echo "✅ Feature branch created: spec/${BRANCH_NAME}" echo "✅ Spec file initialized: $SPEC_FILE" echo "Ready for specification writing." fi