diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 761d017..9f1d9b6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,11 +10,11 @@ jobs: strategy: matrix: os: [ "ubuntu-latest", "macos-latest" ] - go-version: [ "1.18" ] + go-version: [ "1.25.x" ] runs-on: ${{ matrix.os }} steps: - name: setup Go ${{ matrix.go-version }} - uses: actions/setup-go@v3 + uses: actions/setup-go@v6 with: go-version: ${{ matrix.go-version }} - name: checkout @@ -22,7 +22,7 @@ jobs: with: fetch-depth: 0 - name: lint - uses: dominikh/staticcheck-action@v1.2.0 + uses: dominikh/staticcheck-action@v1.3.0 with: version: "2022.1" install-go: false diff --git a/go.mod b/go.mod index e07083e..67ee159 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/mnowotnik/fzshell -go 1.18 +go 1.25 require ( github.com/Masterminds/sprig/v3 v3.0.2 diff --git a/internal/compl/source.go b/internal/compl/source.go index d9eb6c3..f546a86 100644 --- a/internal/compl/source.go +++ b/internal/compl/source.go @@ -3,12 +3,12 @@ package compl import ( "os" "os/exec" - "text/template" fzf "github.com/mnowotnik/fzf/src" "github.com/mnowotnik/fzshell/internal/utils" "github.com/pkg/errors" + "golang.org/x/term" ) type CompletionSource struct { @@ -110,7 +110,7 @@ func (cs *CompletionSource) pipeCommandToFzf(args []string, kwargs map[string]st } } options.Select1 = cs.SelectOne - if returnAll { + if returnAll || !term.IsTerminal(int(os.Stdout.Fd())) || !term.IsTerminal(int(os.Stdin.Fd())) || !term.IsTerminal(int(os.Stderr.Fd())) { var filter string = "" options.Filter = &filter } diff --git a/tests/functional/completions_test.go b/tests/functional/completions_test.go new file mode 100644 index 0000000..4c71535 --- /dev/null +++ b/tests/functional/completions_test.go @@ -0,0 +1,44 @@ +package functional_test + +import ( + "path/filepath" + "testing" +) + +func TestReturnAllOutputsAllItems(t *testing.T) { + configPath := filepath.Join(repoRoot, "tests", "functional", "fixtures", "simple.yaml") + + result := runFzshell(t, []string{"--config", configPath, "--all", "simple"}, "", nil) + + if result.ExitCode != 0 { + t.Fatalf("expected exit code 0, got %d (stderr: %q)", result.ExitCode, result.Stderr) + } + + const expectedOutput = "alpha\nbeta\n" + if result.Stdout != expectedOutput { + t.Fatalf("unexpected stdout: got %q, want %q", result.Stdout, expectedOutput) + } + + if result.Stderr != "" { + t.Fatalf("expected empty stderr, got %q", result.Stderr) + } +} + +func TestReplacementRendersLineBuffer(t *testing.T) { + configPath := filepath.Join(repoRoot, "tests", "functional", "fixtures", "replacement.yaml") + + result := runFzshell(t, []string{"--config", configPath, "ticket 42/build"}, "", nil) + + if result.ExitCode != 0 { + t.Fatalf("expected exit code 0, got %d (stderr: %q)", result.ExitCode, result.Stderr) + } + + const expectedOutput = "ticket 42/build -> 42|build|command:42:build" + if result.Stdout != expectedOutput { + t.Fatalf("unexpected stdout: got %q, want %q", result.Stdout, expectedOutput) + } + + if result.Stderr != "" { + t.Fatalf("expected empty stderr, got %q", result.Stderr) + } +} diff --git a/tests/functional/fixtures/replacement.yaml b/tests/functional/fixtures/replacement.yaml new file mode 100644 index 0000000..7bd4745 --- /dev/null +++ b/tests/functional/fixtures/replacement.yaml @@ -0,0 +1,6 @@ +completions: + - pattern: "ticket (?P[0-9]+)/(\\w+)$" + cmd: "printf 'command:%s:%s\\n' \"$ID\" \"$1\"" + map: "{{ printf \"%s|%s|%s\" .ID ._1 .item }}" + replacement: "ticket {{.ID}}/{{._1}} -> {{.item}}" + selectOne: true diff --git a/tests/functional/fixtures/simple.yaml b/tests/functional/fixtures/simple.yaml new file mode 100644 index 0000000..f6dd023 --- /dev/null +++ b/tests/functional/fixtures/simple.yaml @@ -0,0 +1,3 @@ +completions: + - pattern: "simple$" + cmd: "printf 'alpha\\nbeta\\n'"