Skip to content

feat: add --purge flag to 'starforge template remove'#290

Open
dextro172-ui wants to merge 1 commit into
Nanle-code:masterfrom
dextro172-ui:feat/template-remove-purge
Open

feat: add --purge flag to 'starforge template remove'#290
dextro172-ui wants to merge 1 commit into
Nanle-code:masterfrom
dextro172-ui:feat/template-remove-purge

Conversation

@dextro172-ui
Copy link
Copy Markdown

Description

Adds a --purge flag to starforge template remove that optionally deletes cached/downloaded template assets in addition to registry metadata. Without --purge, only the registry entry is removed (safe default). This gives users explicit control over cleanup depth and prevents accidental deletion of potentially reusable template files.

Closes #253

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Changes Made

Added --purge flag to starforge template remove CLI command via clap argument parser
Split removal logic into two phases: (1) registry metadata deletion, (2) optional cache/asset cleanup
Added TemplateStore::purge() method that removes the template's cache directory and any downloaded archives from ~/.starforge/templates/cache/
Added Registry::remove() method that deletes only the registry entry from ~/.starforge/templates/registry.json
Updated remove command handler to call registry.remove() unconditionally, then conditionally call store.purge() when --purge is passed
Added confirmation prompt for --purge when interactive TTY is detected (bypassed with --yes)
Added --yes flag to skip confirmation prompts for CI/automation use
Updated error handling: purge() returns Err if template assets are in use by another process or if filesystem permissions are insufficient

Testing

How has this been tested?

Describe the tests you ran and how to reproduce them.

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

Test Coverage

Happy path:
starforge template remove my-template → registry entry removed, cache files preserved
starforge template remove my-template --purge → registry entry and cache files both removed
starforge template remove my-template --purge --yes → bypasses confirmation, removes everything
Edge cases:
Remove non-existent template → returns TemplateNotFound error (no filesystem changes)
--purge on template with no cached assets → succeeds (registry removal only, no error)
--purge on template currently in use by another starforge process → returns TemplateInUse error
Registry entry exists but cache directory was manually deleted → --purge succeeds (idempotent)
Error handling:
Insufficient permissions on cache directory → returns PermissionDenied with path context
Corrupted registry JSON → returns RegistryCorrupted error before attempting any filesystem ops
Interrupt (Ctrl+C) during confirmation prompt → graceful exit with no changes

Code Quality Checklist

  • My code follows the style guidelines of this project (cargo fmt)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings (cargo clippy -- -D warnings)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The CI checks pass (format, clippy, tests)

Breaking Changes

  • This PR introduces breaking changes

If checked, describe the breaking changes and migration path:

Documentation

  • README.md updated
  • DEVELOPER_GUIDE.md updated (if applicable)
  • API_REFERENCE.md updated (if applicable)
  • No documentation changes needed

Screenshots (if applicable)

Safe default — only removes registry entry

$ starforge template remove react-starter
✓ Removed 'react-starter' from registry
Cache preserved at ~/.starforge/templates/cache/react-starter/

With purge — full cleanup

$ starforge template remove react-starter --purge
⚠ This will permanently delete template cache and assets for 'react-starter'
Continue? [y/N] y
✓ Removed 'react-starter' from registry
✓ Purged cache (/.starforge/templates/cache/react-starter/)
✓ Purged downloaded archive (
/.starforge/templates/archives/react-starter.tar.gz)

Non-interactive purge

$ starforge template remove react-starter --purge --yes
✓ Removed 'react-starter' from registry
✓ Purged cache and assets

Additional Context

Additional Context
The --purge flag addresses the concern raised in #253 where users wanted a way to fully reclaim disk space from unused templates without manually hunting through ~/.starforge/. The safe default (no --purge) protects against accidental data loss — users may have local modifications in the cached template directory they want to keep even if removing the registry entry.
The confirmation prompt for --purge follows the same pattern used by starforge project delete and starforge registry clean.

- Without --purge: only removes registry metadata (safe default)
- With --purge: also deletes cached and stored template assets
- Implements Nanle-code#253
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 2, 2026

@dextro172-ui Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a template remove --purge option

2 participants