aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2023-09-28 02:41:03 +0100
committerJoop Kiefte <ikojba@gmail.com>2023-09-28 02:41:30 +0100
commitc7d3da71c7b4b77672c7a22a7b7200aab72f028b (patch)
treeff1d980ca5100d43d8f51ebdc491ce9572b077fe
parentda7884cb606b283ac0251f42b71da30710c23ef6 (diff)
Stop trying to be too smart
-rw-r--r--main.go40
1 files changed, 16 insertions, 24 deletions
diff --git a/main.go b/main.go
index 4162148..aca6f64 100644
--- a/main.go
+++ b/main.go
@@ -6,18 +6,16 @@ import (
"os"
"os/exec"
"strings"
- "sync"
"bufio"
)
-var once = sync.Once{}
-
func main() {
var choice int
var table string
var query string
var args []string
var noninteractive bool
+ var err error
if len(os.Args) > 1 {
noninteractive = true
@@ -64,7 +62,10 @@ Running debby with any other arguments will run it as a dolt command.`
}
// Table name will be empty. Run query
- RunSQL(query, "")
+ err = RunSQL(query, "")
+ if err != nil {
+ fmt.Println(err)
+ }
case 2:
if table == "" {
// Request table name
@@ -73,7 +74,10 @@ Running debby with any other arguments will run it as a dolt command.`
}
// Run query
- RunSQL("select * from "+table+";", table)
+ err = RunSQL("select * from "+table+";", table)
+ if err != nil {
+ fmt.Println(err)
+ }
case 3:
if len(args) == 0 {
// Request command. Make dolt bold
@@ -180,7 +184,10 @@ func RunSQL(query, table string) error {
}
// Open the file in visidata
- OpenVisidata(f.Name(), "-f", "csv")
+ err = OpenVisidata(f.Name(), "-f", "csv")
+ if err != nil {
+ return err
+ }
// If table is not empty, save the file to the table
if table != "" {
@@ -195,25 +202,10 @@ func RunSQL(query, table string) error {
return nil
}
-func OpenVisidata(args ...string) {
- vdcmd := "echo No visidata found, trying to run: vd "
- once.Do(func() {
- // run with --version and check if it returns saul.pw/VisiData, if not try the same with visidata instead
- for _, cmd := range []string{"vd", "visidata"} {
- out, err := exec.Command(cmd, "--version").Output()
- if err != nil {
- continue
- }
- if strings.Contains(string(out), "saul.pw/VisiData") {
- vdcmd = cmd
- break
- }
- }
- })
-
- cmd := exec.Command(vdcmd, args...)
+func OpenVisidata(args ...string) error {
+ cmd := exec.Command("visidata", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
- cmd.Run()
+ return cmd.Run()
}