Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions components/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ package main

import (
"bufio"
"context"
"fmt"
"io"
"log"
"os"
"os/user"
"path"
"regexp"

ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
Expand All @@ -30,10 +28,6 @@ import (
"github.com/pingcap/tiup/pkg/repository"
gops "github.com/shirou/gopsutil/process"
"github.com/spf13/cobra"
_ "github.com/xo/usql/drivers/mysql"
"github.com/xo/usql/env"
"github.com/xo/usql/handler"
"github.com/xo/usql/rline"
)

func main() {
Expand Down Expand Up @@ -91,20 +85,11 @@ func connect(target string) error {
return fmt.Errorf("specified instance %s not found, maybe it's not alive now, execute `tiup status` to see instance list", target)
}
}
u, err := user.Current()
if err != nil {
return fmt.Errorf("can't get current user: %s", err.Error())
}
l, err := rline.New(false, "", env.HistoryFile(u))
if err != nil {
return fmt.Errorf("can't open history file: %s", err.Error())
}
h := handler.New(l, u, os.Getenv(localdata.EnvNameInstanceDataDir), true)
if err = h.Open(context.TODO(), ep.dsn); err != nil {
return fmt.Errorf("can't open connection to %s: %s", ep.dsn, err.Error())
}
if err = h.Run(); err != io.EOF {
return err
fmt.Printf("MySQL Shell: mysqlsh %s\n", ep.dsn)
r := regexp.MustCompile(`^mysql://([a-z]+)@(.+):(\d+)`)
m := r.FindStringSubmatch(ep.dsn)
if m != nil {
fmt.Printf("MySQL Client: mysql -u %s -h %s -P %s\n", m[1], m[2], m[3])
}
return nil
}
Expand All @@ -131,6 +116,9 @@ func isInstanceAlive(tiupHome, instance string) bool {
if err != nil {
return false
}
if s == nil {
return false
}
exist, _ := gops.PidExists(int32(s.Pid))
return exist
}
Expand Down Expand Up @@ -185,7 +173,7 @@ func selectEndpoint(endpoints []*endpoint) *endpoint {
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
_ = os.WriteFile("/tmp/log", []byte(e.ID+"\n"), 0664)
_ = os.WriteFile("/tmp/log", []byte(e.ID+"\n"), 0o664)
switch e.ID {
case "q", "<C-c>":
return nil
Expand Down
21 changes: 0 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.10.0
github.com/vishvananda/netlink v0.0.0-20210530105856-14e832ae1e8f
github.com/xo/usql v0.9.5
go.etcd.io/etcd/client/pkg/v3 v3.5.7
go.etcd.io/etcd/client/v3 v3.5.7
go.uber.org/atomic v1.11.0
Expand All @@ -65,24 +64,16 @@ require (
)

require (
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/bigquery v1.64.0 // indirect
cloud.google.com/go/spanner v1.73.0 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/alecthomas/chroma v0.9.4 // indirect
github.com/apache/thrift v0.17.0 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/chavacava/garif v0.1.0 // indirect
github.com/chzyer/test v1.0.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gohxs/readline v0.0.0-20171011095936-a780388e6e7c // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
Expand All @@ -99,10 +90,8 @@ require (
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nathan-fiscaletti/consolesize-go v0.0.0-20210105204122-a87d9f614b9d // indirect
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -116,26 +105,16 @@ require (
github.com/vishvananda/netns v0.0.4 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xo/dburl v0.9.0 // indirect
github.com/xo/tblfmt v0.8.0 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
github.com/zaf/temp v0.0.0-20170209143821-94e385923345 // indirect
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
go.uber.org/goleak v1.2.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/net v0.37.0 // indirect
golang.org/x/tools v0.31.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/api v0.203.0 // indirect
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 // indirect
honnef.co/go/tools v0.4.3 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/sqlite v1.21.2 // indirect
modernc.org/token v1.1.0 // indirect
)

tool (
Expand Down
Loading
Loading