|
| 1 | +# Self-Update System for Codegen CLI |
| 2 | + |
| 3 | +The Codegen CLI includes a simplified self-update system that allows users to easily update to the latest version. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +### 🚀 Smart Update Detection |
| 8 | +- Automatically detects installation method (pip, pipx, uv tool, homebrew, development) |
| 9 | +- Checks for updates periodically (once per day by default) |
| 10 | +- Shows update notifications when new versions are available |
| 11 | +- Fetches stable releases from PyPI |
| 12 | + |
| 13 | +### 🔄 Update Management |
| 14 | +- Update to latest stable version |
| 15 | +- Update to specific versions |
| 16 | +- Dry-run mode to preview changes |
| 17 | +- Legacy mode for simple pip upgrades |
| 18 | + |
| 19 | +### 🛡️ Safety Features |
| 20 | +- Pre-update validation checks |
| 21 | +- Major version update warnings |
| 22 | +- Post-update tips and guidance |
| 23 | + |
| 24 | +### 📊 Version Information |
| 25 | +- List available versions |
| 26 | +- Check for updates without installing |
| 27 | +- View current and latest versions |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +### Basic Commands |
| 32 | + |
| 33 | +```bash |
| 34 | +# Update to latest stable version |
| 35 | +codegen update |
| 36 | + |
| 37 | +# Check for available updates without installing |
| 38 | +codegen update --check |
| 39 | + |
| 40 | +# List available versions |
| 41 | +codegen update --list |
| 42 | + |
| 43 | +# Show version history |
| 44 | +codegen update --history |
| 45 | +``` |
| 46 | + |
| 47 | +### Advanced Options |
| 48 | + |
| 49 | +```bash |
| 50 | +# Update to specific version |
| 51 | +codegen update --version 1.2.3 |
| 52 | + |
| 53 | +# Preview update without making changes |
| 54 | +codegen update --dry-run |
| 55 | + |
| 56 | +# Force update check (bypass cache) |
| 57 | +codegen update --force |
| 58 | + |
| 59 | +# Use legacy pip upgrade method |
| 60 | +codegen update --legacy |
| 61 | +``` |
| 62 | + |
| 63 | +## Release Information |
| 64 | + |
| 65 | +The update system fetches stable releases from PyPI. Pre-release versions are automatically filtered out to ensure stability. Only production-ready versions are shown and available for installation through the update command. |
| 66 | + |
| 67 | +## Installation Methods |
| 68 | + |
| 69 | +The update system automatically detects how Codegen was installed and uses the appropriate update method: |
| 70 | + |
| 71 | +### pip Installation |
| 72 | +```bash |
| 73 | +pip install codegen |
| 74 | +# Updates via: pip install --upgrade codegen |
| 75 | +``` |
| 76 | + |
| 77 | +### pipx Installation |
| 78 | +```bash |
| 79 | +pipx install codegen |
| 80 | +# Updates via: pipx upgrade codegen |
| 81 | +``` |
| 82 | + |
| 83 | +### UV Tool Installation |
| 84 | +```bash |
| 85 | +uv tool install codegen |
| 86 | +# Updates via: uv tool install --upgrade codegen |
| 87 | +``` |
| 88 | + |
| 89 | +### Homebrew Installation (macOS) |
| 90 | +```bash |
| 91 | +brew install codegen |
| 92 | +# Updates via: brew upgrade codegen |
| 93 | +``` |
| 94 | + |
| 95 | +### Development Installation |
| 96 | +For development/editable installs, the update system will notify you to update via git: |
| 97 | +```bash |
| 98 | +git pull origin main |
| 99 | +pip install -e . |
| 100 | +``` |
| 101 | + |
| 102 | +## Update Process |
| 103 | + |
| 104 | +The update system performs a streamlined update process: |
| 105 | + |
| 106 | +### How Updates Work |
| 107 | + |
| 108 | +1. **Version Check**: Fetches available versions from PyPI |
| 109 | +2. **Comparison**: Compares current version with available versions |
| 110 | +3. **Confirmation**: Asks for user confirmation before proceeding |
| 111 | +4. **Installation**: Uses the appropriate package manager to update |
| 112 | +5. **Verification**: Displays success message and restart instructions |
| 113 | + |
| 114 | +### Major Version Updates |
| 115 | + |
| 116 | +When updating to a new major version: |
| 117 | +- The system warns about potential breaking changes |
| 118 | +- Post-update tips are displayed |
| 119 | +- Users are encouraged to check the changelog |
| 120 | + |
| 121 | +## Update Notifications |
| 122 | + |
| 123 | +The CLI checks for updates periodically and shows notifications when new versions are available: |
| 124 | + |
| 125 | +``` |
| 126 | +ℹ️ A new version of Codegen CLI is available: 1.2.3 |
| 127 | +Run 'codegen update' to upgrade |
| 128 | +``` |
| 129 | + |
| 130 | +### Disable Update Checks |
| 131 | + |
| 132 | +To disable automatic update checks, set the environment variable: |
| 133 | + |
| 134 | +```bash |
| 135 | +export CODEGEN_DISABLE_UPDATE_CHECK=1 |
| 136 | +``` |
| 137 | + |
| 138 | +## Downgrading |
| 139 | + |
| 140 | +If an update causes issues, you can downgrade to a previous version: |
| 141 | + |
| 142 | +```bash |
| 143 | +# Downgrade to a specific version |
| 144 | +codegen update --version 1.2.2 |
| 145 | + |
| 146 | +# Or use your package manager directly |
| 147 | +pip install codegen==1.2.2 |
| 148 | +pipx install codegen==1.2.2 --force |
| 149 | +uv tool install codegen==1.2.2 --upgrade |
| 150 | +``` |
| 151 | + |
| 152 | +## Configuration |
| 153 | + |
| 154 | +Update settings are stored in `~/.codegen/`: |
| 155 | + |
| 156 | +- `update_check.json` - Last update check timestamp and cache |
| 157 | + |
| 158 | +## Troubleshooting |
| 159 | + |
| 160 | +### Update Fails |
| 161 | + |
| 162 | +1. Try using the legacy update method: |
| 163 | + ```bash |
| 164 | + codegen update --legacy |
| 165 | + ``` |
| 166 | + |
| 167 | +2. Manually update via pip: |
| 168 | + ```bash |
| 169 | + pip install --upgrade codegen |
| 170 | + ``` |
| 171 | + |
| 172 | +3. Check installation method: |
| 173 | + ```bash |
| 174 | + which codegen |
| 175 | + pip show codegen |
| 176 | + ``` |
| 177 | + |
| 178 | +### Permission Errors |
| 179 | + |
| 180 | +If you get permission errors, you may need to use sudo (not recommended) or update your user installation: |
| 181 | + |
| 182 | +```bash |
| 183 | +# For user installation |
| 184 | +pip install --user --upgrade codegen |
| 185 | + |
| 186 | +# For pipx |
| 187 | +pipx upgrade codegen |
| 188 | +``` |
| 189 | + |
| 190 | +### Downgrade Issues |
| 191 | + |
| 192 | +If you need to downgrade: |
| 193 | + |
| 194 | +1. Use the update command with a specific version: |
| 195 | + ```bash |
| 196 | + codegen update --version 1.2.2 |
| 197 | + ``` |
| 198 | + |
| 199 | +2. Or manually install the desired version: |
| 200 | + ```bash |
| 201 | + pip install codegen==1.2.2 |
| 202 | + pipx install codegen==1.2.2 --force |
| 203 | + uv tool install codegen==1.2.2 --upgrade |
| 204 | + ``` |
| 205 | + |
| 206 | +## Development |
| 207 | + |
| 208 | +### Testing Updates |
| 209 | + |
| 210 | +Test the update system in development: |
| 211 | + |
| 212 | +```bash |
| 213 | +# Check current version |
| 214 | +codegen --version |
| 215 | + |
| 216 | +# Test update check |
| 217 | +codegen update --check --force |
| 218 | + |
| 219 | +# Test dry-run update |
| 220 | +codegen update --dry-run |
| 221 | + |
| 222 | +# Test specific version |
| 223 | +codegen update --version 1.2.3 --dry-run |
| 224 | +``` |
| 225 | + |
| 226 | +### Adding New Features |
| 227 | + |
| 228 | +To add new update features: |
| 229 | + |
| 230 | +1. Modify `updater.py` for core functionality |
| 231 | +2. Update command options in `main.py` |
| 232 | +3. Add tests for new functionality |
| 233 | + |
| 234 | +## API Reference |
| 235 | + |
| 236 | +### UpdateManager Class |
| 237 | + |
| 238 | +```python |
| 239 | +from codegen.cli.commands.update import UpdateManager |
| 240 | + |
| 241 | +manager = UpdateManager() |
| 242 | + |
| 243 | +# Check for updates |
| 244 | +result = manager.check_for_updates(force=True) |
| 245 | + |
| 246 | +# Perform update |
| 247 | +success = manager.perform_update(target_version="1.2.3", dry_run=False) |
| 248 | + |
| 249 | +# Check installation method |
| 250 | +print(manager.install_method) |
| 251 | +``` |
| 252 | + |
| 253 | +### Installation Methods |
| 254 | + |
| 255 | +```python |
| 256 | +from codegen.cli.commands.update.updater import InstallMethod |
| 257 | + |
| 258 | +methods = [ |
| 259 | + InstallMethod.PIP, |
| 260 | + InstallMethod.PIPX, |
| 261 | + InstallMethod.UV_TOOL, |
| 262 | + InstallMethod.HOMEBREW, |
| 263 | + InstallMethod.DEVELOPMENT, |
| 264 | + InstallMethod.UNKNOWN |
| 265 | +] |
| 266 | +``` |
| 267 | + |
| 268 | +## Best Practices |
| 269 | + |
| 270 | +1. **Regular Updates**: Keep your CLI updated for latest features and security fixes |
| 271 | +2. **Check Changelog**: Review breaking changes before major version updates |
| 272 | +3. **Test in Dev**: Test updates in development environment first |
| 273 | +4. **Use Dry Run**: Preview updates with `--dry-run` before applying |
| 274 | +5. **Report Issues**: Report update issues to help improve the system |
| 275 | + |
| 276 | +## Security |
| 277 | + |
| 278 | +- Updates are fetched over HTTPS from PyPI |
| 279 | +- Package signatures are verified by pip/pipx/uv |
| 280 | +- Pre-release versions are filtered out automatically |
| 281 | +- Major version updates require confirmation |
| 282 | + |
| 283 | +## Future Enhancements |
| 284 | + |
| 285 | +- [ ] Automatic rollback on update failure |
| 286 | +- [ ] Configuration migration system |
| 287 | +- [ ] Release notes integration |
| 288 | +- [ ] Beta and nightly release channels |
| 289 | +- [ ] Binary distribution for faster updates |
| 290 | +- [ ] Automatic security update installation |
| 291 | +- [ ] Update progress with detailed logging |
| 292 | +- [ ] Network proxy support |
| 293 | +- [ ] Offline update packages |
0 commit comments