Skip to content

feat: add 'thv logs prune' subcommand to clean up orphaned log files - #517

Merged
JAORMX merged 1 commit into
mainfrom
feature/logs-prune-subcommand
May 30, 2025
Merged

JAORMX merged 1 commit into
mainfrom
feature/logs-prune-subcommand

Conversation

@JAORMX

@JAORMX JAORMX commented May 30, 2025

Copy link
Copy Markdown
Collaborator

Summary

Implements the thv logs prune subcommand as requested in issue #447. This feature allows users to clean up old log files from servers that are no longer managed by ToolHive.

Changes

  • ✅ Added prune subcommand to thv logs
  • ✅ Maintains full backward compatibility with existing thv logs [container-name] functionality
  • ✅ Provides dual access methods: both as subcommand and direct argument
  • ✅ Smart cleanup logic that only removes log files from unmanaged servers
  • ✅ Comprehensive error handling and user feedback
  • ✅ Follows project coding standards (0 linting issues)
  • ✅ Reduced cyclomatic complexity using helper functions

Usage

# Clean up orphaned log files
thv logs prune

# View help for the prune command
thv logs prune --help

# Existing functionality still works unchanged
thv logs fetch
thv logs osv --follow

Testing

  • ✅ Successfully builds without errors
  • ✅ Passes all linting checks
  • ✅ Existing logs functionality verified working
  • ✅ Prune functionality tested with real orphaned files
  • ✅ Edge cases handled (no logs directory, no orphaned files)

Implementation Details

The implementation:

  1. Uses XDG Base Directory specification for log file location
  2. Compares log file names against currently managed container names
  3. Only removes files that don't correspond to any managed container
  4. Provides detailed feedback on what was removed
  5. Handles errors gracefully without stopping the cleanup process

Closes #447

- Implements feature requested in issue #447
- Adds prune subcommand that deletes log files from servers not currently managed by ToolHive
- Maintains backward compatibility with existing 'thv logs [container-name]' functionality
- Provides dual access: 'thv logs prune' as both subcommand and direct argument
- Includes comprehensive error handling and user feedback
- Follows project coding standards with 0 linting issues

Closes #447

Signed-off-by: Juan Antonio Osorio <[email protected]>
@JAORMX
JAORMX force-pushed the feature/logs-prune-subcommand branch from b761fdc to 70a4743 Compare May 30, 2025 14:07
@JAORMX
JAORMX merged commit 0d7e13e into main May 30, 2025
@JAORMX
JAORMX deleted the feature/logs-prune-subcommand branch May 30, 2025 15:00
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.

Idea: thv logs prune subcommand

2 participants