fix(cli): improve completion and Windows live testing

Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com>
Co-authored-by: gagradebnath <salemdebnath@gmail.com>
This commit is contained in:
Peter Steinberger 2026-04-20 16:05:12 +01:00
parent a8531f26b8
commit 4f5e474059
No known key found for this signature in database
6 changed files with 35 additions and 6 deletions

View File

@ -37,9 +37,14 @@ complete -F _gog_complete gog
func zshCompletionScript() string {
return `#compdef gog
autoload -Uz bashcompinit
bashcompinit
` + bashCompletionScript()
_gog() {
local -a completions
completions=("${(@f)$(gog __complete --cword "$((CURRENT - 1))" -- "${words[@]}")}")
_describe 'values' completions
}
compdef _gog gog
`
}
func fishCompletionScript() string {

View File

@ -9,7 +9,7 @@ import (
func TestCompletionCmd(t *testing.T) {
cases := map[string]string{
"bash": "complete -F _gog_complete gog",
"zsh": "bashcompinit",
"zsh": "compdef _gog gog",
"fish": "complete -c gog",
"powershell": "Register-ArgumentCompleter",
}

View File

@ -262,13 +262,13 @@ func ExpandPath(path string) (string, error) {
return home, nil
}
if strings.HasPrefix(path, "~/") {
if strings.HasPrefix(path, "~/") || strings.HasPrefix(path, "~\\") {
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("expand home dir: %w", err)
}
return filepath.Join(home, path[2:]), nil
return filepath.Join(home, strings.TrimLeft(path[2:], `/\`)), nil
}
return path, nil

View File

@ -10,6 +10,7 @@ import (
func TestPaths_CreateDirs(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, "xdg-config"))
dir, err := EnsureDir()
@ -96,6 +97,11 @@ func TestExpandPath(t *testing.T) {
input: "~/Downloads/file.txt",
want: filepath.Join(home, "Downloads/file.txt"),
},
{
name: "tilde with backslash subpath",
input: `~\Downloads\file.txt`,
want: filepath.Join(home, `Downloads\file.txt`),
},
{
name: "absolute path unchanged",
input: "/usr/local/bin",

View File

@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"time"
)
@ -43,6 +44,11 @@ func TestLiveScript(t *testing.T) {
defer cancel()
cmd := exec.CommandContext(ctx, script, args...)
if runtime.GOOS == "windows" {
script = filepath.Join(root, "scripts", "live-test.ps1")
psArgs := append([]string{"-NoProfile", "-ExecutionPolicy", "Bypass", "-File", script}, args...)
cmd = exec.CommandContext(ctx, "powershell.exe", psArgs...)
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()

12
scripts/live-test.ps1 Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env pwsh
$ErrorActionPreference = "Stop"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$bashScript = Join-Path $scriptDir "live-test.sh"
if (Get-Command bash -ErrorAction SilentlyContinue) {
& bash $bashScript @args
exit $LASTEXITCODE
}
throw "bash is required to run scripts/live-test.sh on Windows"