Taskw

taskw clean

Remove all generated files

taskw clean

Remove all files that were generated by Taskw. This helps clean up the workspace when regenerating code or switching configurations.

Usage

taskw clean

Description

The clean command removes all files that were generated by Taskw, including:

  • Route Registration Files - Generated route registration code
  • Dependency Injection Files - Generated Wire dependency injection code
  • Swagger Documentation Files - Generated API documentation

This is useful when you want to:

  • Start fresh with a new generation
  • Switch between different configurations
  • Remove generated files from version control
  • Debug generation issues

Examples

Basic Clean

taskw clean

Example output:

🧹 Cleaning generated files...

● Deleted 3 files:
  - routes_gen.go
  - dependencies_gen.go
  - swagger.json

✅ Clean completed successfully

Clean with Missing Files

taskw clean

Example output when some files don't exist:

🧹 Cleaning generated files...

● Deleted 2 files:
  - routes_gen.go
  - dependencies_gen.go

• Skipped 1 files (not found):
  - swagger.json

✅ Clean completed successfully

Clean with No Files

taskw clean

Example output when no generated files exist:

🧹 Cleaning generated files...

• No generated files found to clean

✅ Clean completed successfully

Files Removed

The clean command removes these types of files:

Generated Code Files

  • routes_gen.go - Route registration code
  • dependencies_gen.go - Wire dependency injection code
  • wire_gen.go - Generated Wire implementation

Documentation Files

  • swagger.json - Swagger API documentation
  • swagger.yaml - Swagger API documentation (YAML format)

Configuration-Dependent Files

The exact files removed depend on your taskw.yaml configuration:

generation:
  routes:
    output_file: "routes_gen.go"      # This file will be removed
  dependencies:
    output_file: "dependencies_gen.go" # This file will be removed

Configuration

The clean command uses the same configuration as the generate command to determine which files to remove:

generation:
  routes:
    enabled: true
    output_file: "routes_gen.go"
  dependencies:
    enabled: true
    output_file: "dependencies_gen.go"

Custom Output Files

If you've configured custom output file names, the clean command will remove those files:

generation:
  routes:
    output_file: "my_routes.go"      # Will remove my_routes.go
  dependencies:
    output_file: "my_deps.go"        # Will remove my_deps.go

Safety Features

File Validation

The clean command only removes files that match the configured output file names. It won't accidentally delete:

  • Source code files
  • Configuration files
  • Documentation files
  • Any other project files

Dry Run Mode

While not currently implemented, future versions may include a dry-run mode to preview what would be deleted:

taskw clean --dry-run

Common Use Cases

Regenerating Code

# Clean existing generated files
taskw clean

# Generate fresh code
taskw generate

Switching Configurations

# Clean current configuration
taskw clean

# Update taskw.yaml
# ... edit configuration ...

# Generate with new configuration
taskw generate

Debugging Generation Issues

# Clean all generated files
taskw clean

# Scan to verify configuration
taskw scan

# Generate step by step
taskw generate routes
taskw generate deps

Version Control

Remove generated files before committing:

# Clean generated files
taskw clean

# Add source files to git
git add .

# Commit changes
git commit -m "Update handlers and providers"

Integration with Other Commands

Clean and Generate Workflow

# Complete regeneration workflow
taskw clean
taskw scan
taskw generate

Clean and Init Workflow

# Clean existing project
taskw clean

# Initialize new project structure
taskw init github.com/user/new-project

Error Handling

The clean command handles various scenarios gracefully:

File System Errors

  • Permission Denied - Reports error but continues with other files
  • File Not Found - Skips missing files (not an error)
  • Directory Issues - Reports configuration problems

Configuration Errors

  • Invalid Output Paths - Reports configuration issues
  • Missing Configuration - Uses default file names

Exit Codes

  • 0 - Clean completed successfully
  • 1 - Clean failed due to errors
  • 2 - Configuration error

Performance

The clean command is very fast as it only needs to:

  • Read configuration
  • Check file existence
  • Remove files

For typical projects, the clean command completes in milliseconds.

Best Practices

Regular Cleanup

Clean generated files regularly to avoid confusion:

# Before major changes
taskw clean

# After switching branches
taskw clean
taskw generate

Version Control

Don't commit generated files to version control:

# Add to .gitignore
echo "routes_gen.go" >> .gitignore
echo "dependencies_gen.go" >> .gitignore
echo "swagger.json" >> .gitignore

CI/CD Integration

Use clean in your build pipeline:

# In your CI configuration
- name: Clean generated files
  run: taskw clean

- name: Generate code
  run: taskw generate

- name: Build project
  run: go build ./...