feat: Enhanced completion with caching for compartment IDs #1024
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.
Enhanced Completion with Caching for OCI CLI
Summary
This PR adds an enhanced completion system with caching capabilities to the OCI CLI, significantly improving the performance of autocompletion for resource identifiers, particularly compartment IDs.
Problem
Currently, the OCI CLI's autocompletion for parameters like
--compartment-idmakes real-time API calls every time, which can be slow and impact user experience, especially in environments with high latency or when working with tenancies that have many compartments.Solution
This PR introduces:
Key Features
1. Compartment Caching
oci iam compartment list~/.oci/completion_cache/directory2. Enhanced Completion Module
CompartmentCompleterclass for intelligent compartment completionOCIDCacheclass for generic OCID caching3. Cache Management Commands
New commands added under
oci setup:Implementation Details
Files Added:
src/interactive/enhanced_completions.py- Core caching and completion logicsrc/interactive/enable_enhanced_completions.py- Integration modulesrc/oci_cli/custom_types/cli_completion_cache.py- CLI commands for cache managementFiles Modified:
src/interactive/cli_interactive.py- Enable enhanced completions on interactive mode startsrc/oci_cli/cli_setup.py- Add cache management commandsBenefits
Testing
Manual Testing Steps:
pip install -e .oci -ioci setup completion-cache-statusoci setup completion-cache-refreshoci setup completion-cache-clearPerformance Comparison:
Backward Compatibility
Future Enhancements
Potential future improvements:
Checklist
Notes
This implementation focuses on compartment IDs as they are among the most frequently used parameters in OCI CLI. The architecture is designed to be extensible for other resource types in the future.
The cache is profile and region-aware, ensuring that cached data is properly isolated between different OCI configurations.