#!/bin/bash # create-new-feature.sh - Spec-Driven Development Feature Creator # Usage: ./create-new-feature.sh --json "feature description" set -e FEATURE_DESCRIPTION="" JSON_OUTPUT=false # Parse arguments while [[ $# -gt 0 ]]; do case $1 in --json) JSON_OUTPUT=true FEATURE_DESCRIPTION="$2" shift 2 ;; *) FEATURE_DESCRIPTION="$1" shift ;; esac done if [ -z "$FEATURE_DESCRIPTION" ]; then echo "Error: Feature description required" exit 1 fi # Generate branch name from feature description BRANCH_NAME=$(echo "$FEATURE_DESCRIPTION" | \ tr '[:upper:]' '[:lower:]' | \ sed 's/[^a-z0-9]/-/g' | \ sed 's/--*/-/g' | \ sed 's/^-\|-$//g' | \ cut -c1-50) # Add feature prefix if not present if [[ ! "$BRANCH_NAME" =~ ^feature\/ ]]; then BRANCH_NAME="feature/$BRANCH_NAME" fi # Get current directory (should be repo root) REPO_ROOT=$(pwd) SPEC_FILE="$REPO_ROOT/.specify/specs/${BRANCH_NAME#feature/}.md" # Create directories if they don't exist mkdir -p "$(dirname "$SPEC_FILE")" # Create and checkout new branch git checkout -b "$BRANCH_NAME" 2>/dev/null || git checkout "$BRANCH_NAME" # Create initial spec file cat > "$SPEC_FILE" << 'EOF' # Feature Specification ## Overview [Feature description will be populated] ## Requirements [Requirements will be populated] ## Technical Design [Technical design will be populated] ## Implementation Plan [Implementation plan will be populated] ## Testing Strategy [Testing strategy will be populated] EOF # Output results if [ "$JSON_OUTPUT" = true ]; then echo "{\"BRANCH_NAME\":\"$BRANCH_NAME\",\"SPEC_FILE\":\"$SPEC_FILE\"}" else echo "Branch created: $BRANCH_NAME" echo "Spec file: $SPEC_FILE" fi