mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 20:17:45 +00:00
Implements 6-phase CLI UX improvement plan with comprehensive error handling, interactive features, and cross-platform consistency. ### Added - Shell auto-completion (bash, zsh, PowerShell, Fish) - Error codes (E101-E901) with documentation URLs - Fuzzy matching "Did you mean?" suggestions (Levenshtein distance) - Progress indicators (doctor [n/9] counter, GLMT proxy spinner) - Interactive confirmation prompts with --yes/-y automation flag - JSON output format (--json) for auth commands - Impact display (session count, paths) before destructive operations - Comprehensive test suite (15 tests, 100% pass rate) - Complete error documentation in docs/errors/ - Cross-platform `--shell-completion` command ### Changed - Error boxes: Unicode (╔═╗) → ASCII (===) for compatibility - JSON output uses CCS version instead of schema version - Help text includes EXAMPLES section across platforms - Test suite properly counts test cases (not assertions) ### Fixed - --yes flag bug (returned false instead of true) - Help text consistency (added Uninstall section to bash) - Test pass rate calculation (excludes skipped tests) - Help section comparison (locale-specific sort) ### Testing - 13/13 tests passing (2 legitimately skipped) - Cross-platform verified (Node.js, bash, PowerShell) - All error codes documented and tested
158 lines
5.6 KiB
PowerShell
158 lines
5.6 KiB
PowerShell
# PowerShell completion for CCS (Claude Code Switch)
|
|
# Compatible with PowerShell 5.1+
|
|
#
|
|
# Installation:
|
|
# Add to your PowerShell profile ($PROFILE):
|
|
# . /path/to/ccs/scripts/completion/ccs.ps1
|
|
#
|
|
# Or install for current user:
|
|
# Copy-Item scripts/completion/ccs.ps1 ~\Documents\PowerShell\Scripts\
|
|
# Add to profile: . ~\Documents\PowerShell\Scripts\ccs.ps1
|
|
|
|
Register-ArgumentCompleter -CommandName ccs -ScriptBlock {
|
|
param($commandName, $wordToComplete, $commandAst, $fakeBoundParameters)
|
|
|
|
$commands = @('auth', 'doctor', '--help', '--version', '-h', '-v')
|
|
$authCommands = @('create', 'list', 'show', 'remove', 'default', '--help', '-h')
|
|
$listFlags = @('--verbose', '--json')
|
|
$removeFlags = @('--yes', '-y')
|
|
$showFlags = @('--json')
|
|
|
|
# Get current position in command
|
|
$words = $commandAst.ToString() -split '\s+' | Where-Object { $_ -ne '' }
|
|
$position = $words.Count
|
|
|
|
# Helper function to get profiles
|
|
function Get-CcsProfiles {
|
|
param([string]$Type = 'all')
|
|
|
|
$profiles = @()
|
|
|
|
# Settings-based profiles
|
|
if ($Type -in @('all', 'settings')) {
|
|
$configPath = "$env:USERPROFILE\.ccs\config.json"
|
|
if (Test-Path $configPath) {
|
|
try {
|
|
$config = Get-Content $configPath -Raw | ConvertFrom-Json
|
|
$profiles += $config.profiles.PSObject.Properties.Name
|
|
} catch {}
|
|
}
|
|
}
|
|
|
|
# Account-based profiles
|
|
if ($Type -in @('all', 'account')) {
|
|
$profilesPath = "$env:USERPROFILE\.ccs\profiles.json"
|
|
if (Test-Path $profilesPath) {
|
|
try {
|
|
$data = Get-Content $profilesPath -Raw | ConvertFrom-Json
|
|
$profiles += $data.profiles.PSObject.Properties.Name
|
|
} catch {}
|
|
}
|
|
}
|
|
|
|
return $profiles | Sort-Object -Unique
|
|
}
|
|
|
|
# Top-level completion
|
|
if ($position -eq 2) {
|
|
$allOptions = $commands + (Get-CcsProfiles)
|
|
$allOptions | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
[System.Management.Automation.CompletionResult]::new(
|
|
$_,
|
|
$_,
|
|
'ParameterValue',
|
|
$_
|
|
)
|
|
}
|
|
return
|
|
}
|
|
|
|
# auth subcommand completion
|
|
if ($words[1] -eq 'auth') {
|
|
if ($position -eq 3) {
|
|
# auth subcommands
|
|
$authCommands | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
[System.Management.Automation.CompletionResult]::new(
|
|
$_,
|
|
$_,
|
|
'ParameterValue',
|
|
$_
|
|
)
|
|
}
|
|
} elseif ($position -eq 4) {
|
|
# Profile names or flags for auth subcommands
|
|
switch ($words[2]) {
|
|
'show' {
|
|
$options = (Get-CcsProfiles -Type account) + $showFlags
|
|
$options | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
[System.Management.Automation.CompletionResult]::new(
|
|
$_,
|
|
$_,
|
|
'ParameterValue',
|
|
$_
|
|
)
|
|
}
|
|
}
|
|
'remove' {
|
|
$options = (Get-CcsProfiles -Type account) + $removeFlags
|
|
$options | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
[System.Management.Automation.CompletionResult]::new(
|
|
$_,
|
|
$_,
|
|
'ParameterValue',
|
|
$_
|
|
)
|
|
}
|
|
}
|
|
'default' {
|
|
Get-CcsProfiles -Type account | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
[System.Management.Automation.CompletionResult]::new(
|
|
$_,
|
|
$_,
|
|
'ParameterValue',
|
|
$_
|
|
)
|
|
}
|
|
}
|
|
'list' {
|
|
$listFlags | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
[System.Management.Automation.CompletionResult]::new(
|
|
$_,
|
|
$_,
|
|
'ParameterValue',
|
|
$_
|
|
)
|
|
}
|
|
}
|
|
'create' {
|
|
# No completion for create (user types new name)
|
|
}
|
|
}
|
|
} elseif ($position -eq 5) {
|
|
# Flags after profile name
|
|
switch ($words[2]) {
|
|
'show' {
|
|
$showFlags | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
[System.Management.Automation.CompletionResult]::new(
|
|
$_,
|
|
$_,
|
|
'ParameterValue',
|
|
$_
|
|
)
|
|
}
|
|
}
|
|
'remove' {
|
|
$removeFlags | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
[System.Management.Automation.CompletionResult]::new(
|
|
$_,
|
|
$_,
|
|
'ParameterValue',
|
|
$_
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|