Project Cleanup¶
The thothctl project cleanup command helps you maintain clean and organized projects by removing residual files and directories that are not needed for the project's operation. This includes temporary files, build artifacts, and other unnecessary items that can clutter your project.
Command Syntax¶
Options¶
| Option | Description |
|---|---|
-cfd, --clean-additional-folders TEXT |
Add folders to clean, specified as a comma-separated list (e.g., -cfd folder_1,folder_2) |
-cfs, --clean-additional-files TEXT |
Add files to clean, specified as a comma-separated list (e.g., -cfs file_1,file_2) |
--help |
Show help message and exit |
Default Cleanup Behavior¶
By default, the project cleanup command removes common temporary files and directories that are typically not needed in a clean project, such as:
.terraformdirectories (Terraform cache).terragrunt-cachedirectories (Terragrunt cache).terraform.lock.hclfiles (Terraform dependency locks)terraform.tfstateandterraform.tfstate.backupfiles (local state files).DS_Storefiles (macOS metadata)__pycache__directories (Python bytecode cache).pytest_cachedirectories (pytest cache)- Various log files and temporary files
Custom Cleanup¶
You can extend the default cleanup behavior by specifying additional files and directories to remove:
Cleaning Additional Folders¶
# Clean up default items plus custom folders
thothctl project cleanup --clean-additional-folders node_modules,dist,build
# Clean up multiple specific folders
thothctl project cleanup -cfd logs,temp,output
Cleaning Additional Files¶
# Clean up default items plus custom files
thothctl project cleanup --clean-additional-files config.local.json,secrets.txt
# Clean up multiple specific files
thothctl project cleanup -cfs *.log,*.tmp,*.bak
Combining Options¶
You can combine both options to clean up both additional folders and files:
# Clean up custom folders and files
thothctl project cleanup -cfd node_modules,dist -cfs *.log,*.tmp
Examples¶
Basic Cleanup¶
Cleaning Terraform-related Files¶
# Clean up Terraform-specific files and directories
thothctl project cleanup -cfd .terraform,.terragrunt-cache -cfs terraform.tfstate,terraform.tfstate.backup,.terraform.lock.hcl
Cleaning Build Artifacts¶
Cleaning Temporary Files¶
Best Practices¶
- Version Control: Always commit important changes before running cleanup to avoid losing work
- Gitignore: Use
.gitignorefiles to prevent committing temporary files rather than cleaning them repeatedly - Regular Cleanup: Incorporate cleanup into your regular workflow to keep projects tidy
- Verify Before Cleaning: Review what will be cleaned before running the command on important projects
- Project-specific Cleanup: Create project-specific cleanup scripts for recurring cleanup tasks
Integration with Development Workflow¶
Pre-commit Hook¶
You can add a cleanup step to your pre-commit hook to ensure your commits don't include unnecessary files:
# Create a pre-commit hook
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
echo "Cleaning up project..."
thothctl project cleanup
git add .
EOF
chmod +x .git/hooks/pre-commit
CI/CD Pipeline¶
You can include cleanup in your CI/CD pipeline to ensure clean builds:
# GitHub Actions example
name: Build and Test
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install thothctl
- name: Clean up project
run: thothctl project cleanup
- name: Build and test
run: |
# Your build and test commands here
Common Use Cases¶
Preparing for Deployment¶
Clean up unnecessary files before deploying to reduce package size:
# Clean up before packaging
thothctl project cleanup
# Package the application
tar -czf app.tar.gz .
Freeing Disk Space¶
Remove large temporary directories to free up disk space:
Preparing for Code Review¶
Clean up before submitting code for review to focus on relevant changes:
# Clean up before creating a pull request
thothctl project cleanup
git add .
git commit -m "feat: Add new feature"
git push
Troubleshooting¶
Clean up cached files when troubleshooting build or runtime issues: