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:
parent
a8531f26b8
commit
4f5e474059
@ -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 {
|
||||
|
||||
@ -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",
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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
12
scripts/live-test.ps1
Normal 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"
|
||||
Loading…
Reference in New Issue
Block a user