usql reads its input through github.com/xo/rline and the usql grammar of github.com/xo/transit (W36). They replace gohxs/readline, usql's own rline package and the stmt package, which are deleted. - feed is new. It parses input with the usql grammar, holds psql's query buffer, says when an entry typed in the editor is finished, and feeds statements and meta commands one at a time, from the editor or from lines. It expands variables when a statement runs, by the range of each variable, so a value is never read again: a defined :'x' no longer opens a string, and the second colon of :: is no longer a variable. - metacmd reads the arguments of a meta command from the grammar. \g reads its option list from the grammar. - handler reads through feed, and talks to the user through rline. -o goes to the handler's output, as \o does, and -c runs through RunCommand. - drivers picks the family of the grammar with Language, from dbmeta's Syntax. The chroma lexer and the styles package are removed, so input has no color until transit's SQL grammars come. - A driver's own Version wins over dbmeta's, so InfluxDB shows its release from GET /ping (dbmeta's D166). - The completer is an rline.Completer. - Color is off unless both input and output are a terminal, because rline writes an escape code to a pipe. usql builds against local checkouts of dbmeta, rline and transit through a go.work that is not committed, because none of them has a tag. docs/PROGRESS.md says how to build, and what is left. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
924 B
Go
41 lines
924 B
Go
package handler
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"os/user"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/go-git/go-billy/v5/memfs"
|
|
"github.com/xo/rline"
|
|
"github.com/xo/usql/feed"
|
|
)
|
|
|
|
// TestRunCommandMetaCommand checks that the text of -c runs a meta command
|
|
// that stands alone.
|
|
func TestRunCommandMetaCommand(t *testing.T) {
|
|
// stdout captures what the meta command writes
|
|
stdout := new(bytes.Buffer)
|
|
l, err := rline.New(
|
|
rline.WithStdin(strings.NewReader("")),
|
|
rline.WithStdout(stdout),
|
|
rline.WithStderr(io.Discard),
|
|
rline.WithColor(false),
|
|
)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer l.Close()
|
|
h, err := New(l, feed.NewLines(strings.NewReader("")), &user.User{}, ".", memfs.New(), true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := h.RunCommand(`\echo hello`); err != nil {
|
|
t.Fatalf("RunCommand: %v", err)
|
|
}
|
|
if got, want := stdout.String(), "hello\n"; got != want {
|
|
t.Fatalf("stdout = %q, want %q", got, want)
|
|
}
|
|
}
|