Skip to content

Conversation

@butschster
Copy link
Collaborator

@butschster butschster commented Mar 14, 2025

This PR adds a new self-update command (with update alias) to the Context Generator CLI, allowing users to automatically update to the latest version without manually downloading the PHAR file.

Features

  • Fetches latest release information from GitHub API
  • Compares current version with latest available version
  • Downloads the new PHAR file if an update is available
  • Handles HTTP redirects for GitHub release assets
  • Performs platform-specific file operations (Windows vs Unix)
  • Provides clear user feedback during the update process
  • Requires confirmation before updating
  • Supports PSR-18 HTTP clients (requires a client to be available)

Usage

# Check for and apply updates
ctx self-update

# Using the alias
ctx  update

Refactor GitHub API Interaction Architecture

This PR introduces a significant architectural improvement to how the context generator interacts with the GitHub API. The changes extract all API interactions into a dedicated client class, resulting in better separation of concerns, improved testability, and more maintainable code.

Key Changes

  1. New GithubClientInterface and implementation:
    • Created a dedicated interface for GitHub API interactions
    • Implemented a concrete client that handles authentication, error handling, and API requests

HTTP Client Refactoring

Problem

Currently, several classes in our codebase need to check if HTTP client dependencies (PSR-18) are available before making HTTP requests. This creates unnecessary duplication and leaks implementation details across the system.

I've refactored the HTTP client implementation to follow better dependency injection principles and the Factory pattern:

  1. Created an HttpClientFactory to centralize dependency checks and client instantiation
  2. Implemented a NullHttpClient (Null Object pattern) that gracefully handles missing dependencies

- Adds a new CLI command to update Context Generator to the latest version

2. implement HTTP client interface and refactor commands and fetchers to use it
- Extract GitHub API interactions into dedicated GitHubClient class
- Improve separation of concerns and testability
Replace hardcoded PHAR path in SelfUpdateCommand with a command-line option
to make the command more flexible for different installation setups.

Changes:
- Remove hardcoded $pharPath parameter from the constructor
- Add a --phar-path (-p) command option with the previous default
- Update execution logic to use the provided option value
- Maintain backward compatibility with the default path

This allows users to run self-update on installations with non-standard
paths: context-generator self-update --phar-path=/custom/path/to/context-generator.phar

2. Fix version command to suggest using self-update command

Update the VersionCommand to suggest using the built-in self-update command
as the primary update method when a new version is detected, while keeping
alternative methods as fallbacks.

3. Introduce 'ctx' as a shorter, more convenient command alias for 'context-generator'
@butschster butschster added documentation Improvements or additions to documentation enhancement New feature or request labels Mar 14, 2025
@butschster butschster merged commit 2a8b96f into main Mar 14, 2025
7 of 8 checks passed
@butschster butschster deleted the feature/self-update branch March 14, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants