feat: add --purge flag to 'starforge template remove'#290
Open
dextro172-ui wants to merge 1 commit into
Open
Conversation
- Without --purge: only removes registry metadata (safe default) - With --purge: also deletes cached and stored template assets - Implements Nanle-code#253
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.
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
cargo fmt)cargo clippy -- -D warnings)Breaking Changes
If checked, describe the breaking changes and migration path:
Documentation
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/)/.starforge/templates/archives/react-starter.tar.gz)✓ Purged downloaded archive (
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.