Skip to content

CLI and Generation Package Improvements

This document outlines the organizational improvements made to the CLI and generation packages for better developer experience.

Summary of Changes

1. Modular CLI Structure

Before: Single monolithic main.py file (1276 lines) mixing all concerns After: Organized into focused command modules:

  • commands/generation.py - All code generation commands
  • commands/infrastructure.py - Terraform wrapper commands
  • commands/synthesis.py - App synthesis and deployment
  • main.py - Clean entry point (139 lines)

2. Unified Generation API

Before: Scattered entry points across multiple modules After: Single unified API in nf.generation.api:

from nf.generation import (
    generate_provider,  # Generate single provider
    generate_providers,  # Generate multiple providers
    generate_functions,  # Generate Terraform functions
    generate_imports,  # Generate import configs
    PROVIDER_SETS,  # Predefined provider sets
)

3. Consolidated Provider Commands

Before: Multiple overlapping commands: - nf generate providers - nf generate batch - nf generate example-config

After: Streamlined commands: - nf generate providers <name> - Single provider - nf generate providers <name...> or --set - Multiple providers - nf generate list-sets - Show available provider sets

4. Improved Command Organization

Before: Mixed concerns at top level After: Logical grouping:

  • Synthesis: synth, deploy
  • Infrastructure: init, plan, apply, destroy, diff
  • Generation: All under nf generate subcommand
  • Stack Management: list-stacks, shell, cd

5. Better Developer Experience

  • Consistent command patterns
  • Predefined provider sets (common, cloud, kubernetes, utils)
  • Helpful nf help command with examples
  • Programmatic API for all generation tasks

Usage Examples

CLI Usage

# Generate a provider
nf generate providers hashicorp/aws

# Generate multiple providers
nf generate providers hashicorp/aws hashicorp/google
nf generate providers --set common

# See available sets
nf generate list-sets

# Generate functions
nf generate functions --legacy-binary tofu

# Full deployment workflow
nf synth
nf deploy --auto-approve

Programmatic Usage

from nf.generation import generate_provider, generate_providers, PROVIDER_SETS

# Generate single provider
generate_provider("hashicorp/aws", output_dir="providers/hashicorp/aws")

# Generate multiple providers
providers = PROVIDER_SETS["common"]
results = generate_providers(providers, parallel=True)

# Generate functions
from nf.generation import generate_functions

generate_functions(legacy_binary="tofu")

Benefits

  1. Reduced Complexity: Main CLI file reduced from 1276 to 139 lines
  2. Better Discoverability: Logical command grouping and unified API
  3. Maintainability: Each module has a focused responsibility
  4. Consistency: Similar operations follow similar patterns
  5. Flexibility: Both CLI and programmatic access to all features