-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (52 loc) · 1.44 KB
/
main.go
File metadata and controls
61 lines (52 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"atlas.sql/internal/db"
"atlas.sql/internal/ui"
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
)
var Version = "dev"
func main() {
if len(os.Args) > 1 && (os.Args[1] == "-v" || os.Args[1] == "--version") {
fmt.Printf("atlas.sql v%s\n", Version)
return
}
if len(os.Args) > 1 && (os.Args[1] == "-h" || os.Args[1] == "--help") {
showHelp()
return
}
if len(os.Args) < 2 {
showHelp()
os.Exit(1)
}
connStr := os.Args[1]
database, err := db.Connect(connStr)
if err != nil {
fmt.Fprintf(os.Stderr, "Error connecting to database: %v\n", err)
os.Exit(1)
}
defer database.Close()
p := tea.NewProgram(ui.NewModel(database), tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running program: %v\n", err)
os.Exit(1)
}
}
func showHelp() {
fmt.Println("Atlas SQL - Terminal-based SQL client")
fmt.Println("\nUsage:")
fmt.Println(" atlas.sql [connection_string]")
fmt.Println("\nExamples:")
fmt.Println(" SQLite: atlas.sql sqlite://path/to/db.sqlite")
fmt.Println(" PostgreSQL: atlas.sql \"postgres://user:pass@localhost:5432/dbname?sslmode=disable\"")
fmt.Println("\nControls:")
fmt.Println(" Enter: Run Query")
fmt.Println(" Tab: Switch focus")
fmt.Println(" Arrows: Navigate Results / Columns")
fmt.Println(" +/-: Adjust Column Width")
fmt.Println(" v: Detail View")
fmt.Println(" c: Copy CSV")
fmt.Println(" h: Show Help")
fmt.Println(" q: Quit")
}