Skip to main content

CLI tool to automate git worktree and Docker Compose development workflows

Project description

sprout

A CLI tool to automate git worktree and Docker Compose development workflows.

Features

  • ๐ŸŒฑ Create isolated development environments using git worktrees
  • ๐Ÿ”ง Automatic .env file generation from templates
  • ๐Ÿšข Smart port allocation to avoid conflicts
  • ๐Ÿ“ Centralized worktree management in .sprout/ directory
  • ๐ŸŽจ Beautiful CLI interface with colors and tables

Installation

pip install sprout

For development:

# Clone the repository
git clone https://github.com/SecDev-Lab/sprout.git
cd sprout

# Install in development mode
pip install -e ".[dev]"

Quick Start

  1. Create a .env.example template in your project root (and optionally in subdirectories):
# API Configuration
API_KEY={{ API_KEY }}
API_PORT={{ auto_port() }}

# Database Configuration  
DB_HOST=localhost
DB_PORT={{ auto_port() }}

# Example: Docker Compose variables (preserved as-is)
# sprout will NOT process ${...} syntax - it's passed through unchanged
# DB_NAME=${DB_NAME}

For monorepo or multi-service projects, you can create .env.example files in subdirectories:

repo/
  .env.example          # Root configuration
  service-a/
    .env.example        # Service A specific config
  service-b/
    .env.example        # Service B specific config
  1. Create and navigate to a new development environment in one command:
cd $(sprout create feature-branch --path)

This single command:

  • Creates a new git worktree for feature-branch
  • Generates a .env file from your template
  • Outputs the path to the new environment
  • Changes to that directory when wrapped in cd $(...)
  1. Start your services:
docker compose up -d

Alternative: Two-Step Process

If you prefer to see the creation output first:

# Create the environment
sprout create feature-branch

# Then navigate to it
cd $(sprout path feature-branch)

Commands

sprout create <branch-name> [--path]

Create a new development environment with automated setup.

Options:

  • --path: Output only the worktree path (useful for shell command substitution)

Examples:

# Create and see progress messages
sprout create feature-xyz

# Create and navigate in one command
cd $(sprout create feature-xyz --path)

sprout ls

List all managed development environments with their status.

The output includes index numbers that can be used with other commands:

sprout ls
# Output:
# โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
# โ”ƒ No.  โ”ƒ Branch          โ”ƒ Path            โ”ƒ Status โ”ƒ Last Modified    โ”ƒ
# โ”กโ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
# โ”‚ 1    โ”‚ feature-auth    โ”‚ .sprout/feat... โ”‚        โ”‚ 2025-06-27 14:30 โ”‚
# โ”‚ 2    โ”‚ bugfix-api      โ”‚ .sprout/bugf... โ”‚        โ”‚ 2025-06-27 15:45 โ”‚
# โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

sprout rm <branch-name-or-index>

Remove a development environment (with confirmation prompts).

You can use either the branch name or the index number from sprout ls:

# Remove by branch name
sprout rm feature-auth

# Remove by index number
sprout rm 1

sprout path <branch-name-or-index>

Get the filesystem path of a development environment.

You can use either the branch name or the index number from sprout ls:

# Get path by branch name
sprout path feature-auth
# Output: /path/to/project/.sprout/feature-auth

# Get path by index number
sprout path 1
# Output: /path/to/project/.sprout/feature-auth

# Use with cd command
cd $(sprout path 2)

sprout --version

Show the version of sprout.

Template Syntax

sprout supports two types of placeholders in .env.example:

  1. Variable Placeholders: {{ VARIABLE_NAME }}

    • First: Checks if the variable exists in your environment (e.g., export API_KEY=xxx)
    • Then: If not found in environment, prompts for user input
    • Example: {{ API_KEY }} will use $API_KEY if set, otherwise asks you to enter it
  2. Auto Port Assignment: {{ auto_port() }}

    • Automatically assigns available ports
    • Avoids conflicts across ALL services in ALL sprout environments
    • Checks system port availability
    • Ensures global uniqueness even in monorepo setups
  3. Docker Compose Syntax (Preserved): ${VARIABLE}

    • NOT processed by sprout - passed through as-is
    • Useful for Docker Compose variable substitution
    • Example: ${DB_NAME:-default} remains unchanged in generated .env

Environment Variable Resolution Example

# Set environment variable
export API_KEY="my-secret-key"

# Create sprout environment - API_KEY will be automatically used
sprout create feature-branch
# โ†’ API_KEY in .env will be set to "my-secret-key" without prompting

# For unset variables, sprout will prompt
sprout create another-branch
# โ†’ Enter a value for 'DATABASE_URL': [user input required]

Monorepo Tutorial

Try out the monorepo functionality with the included sample:

  1. Navigate to the sample monorepo:

    cd sample/monorepo
    
  2. Set required environment variables:

    export API_KEY="your-api-key"
    export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/myapp"
    export REACT_APP_API_KEY="your-frontend-api-key"
    export JWT_SECRET="your-jwt-secret"
    export SMTP_USER="your-smtp-username"
    export SMTP_PASS="your-smtp-password"
    
  3. Create a development environment:

    sprout create monorepo-feature
    
  4. Navigate to the created environment:

    cd .sprout/monorepo-feature
    
  5. Verify all services have unique ports:

    find . -name "*.env" -exec echo "=== {} ===" \; -exec cat {} \;
    
  6. Start all services:

    cd sample/monorepo
    docker-compose up -d
    

The sample includes:

  • Root service: Database and Redis with shared configuration
  • Frontend: React app with API integration
  • Backend: REST API with authentication
  • Shared: Utilities with message queue and monitoring

Each service gets unique, conflict-free ports automatically!

Documentation

Development

Setup

# Install development dependencies
make setup

Testing

# Run tests
make test

# Run tests with coverage
make test-cov

Code Quality

# Run linter
make lint

# Format code
make format

# Run type checking
make typecheck

Requirements

  • Python 3.11+
  • Git
  • Docker Compose (optional, for Docker-based workflows)

License

See LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sprout_cli-0.4.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sprout_cli-0.4.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file sprout_cli-0.4.0.tar.gz.

File metadata

  • Download URL: sprout_cli-0.4.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for sprout_cli-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8bdfa61fb512dd3c2998d4601cf067792f231046f8b32931ef0f9ae93552044a
MD5 30dcf6227f23fc018d310a844968270e
BLAKE2b-256 ddd76c8569d28c8f6e372dc1343a0ec61ed8b08bc05c2ca3abdc9e2f3dff2874

See more details on using hashes here.

File details

Details for the file sprout_cli-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: sprout_cli-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for sprout_cli-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68345caf9468d47b48e2395665744ac2842016688fcbf226b6c5c61e153e38b3
MD5 dcc4805d14dcb2be68e35e21d0920d42
BLAKE2b-256 524e78c21559cfac117d9c962ddc6cc8ebb73608e55fe26dc29e7845a2f94877

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page