-
Notifications
You must be signed in to change notification settings - Fork 0
/
infoSubcmd.go
47 lines (38 loc) · 1.01 KB
/
infoSubcmd.go
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
package main
import (
"database/sql"
"flag"
"fmt"
log "github.com/sirupsen/logrus"
)
// parse args of the info subcommand and exec it
func infoSubcmd(args []string) {
infoCmd := flag.NewFlagSet("info", flag.ExitOnError)
infoCmd.SetOutput(flag.CommandLine.Output())
infoCmd.Usage = func() {
fmt.Fprint(infoCmd.Output(), "Display database system configuration information\n\n")
fmt.Fprintf(infoCmd.Output(), "Usage of orunmila info:\n")
infoCmd.PrintDefaults()
fmt.Fprintln(infoCmd.Output(), "\texample: orunmila [-db <db_path>] info")
}
// nothing to parse, just there to trigger the usage menu
infoCmd.Parse(args)
dsn := fmt.Sprintf("file:%s?mode=rw", *dbPtr)
db, err := sql.Open("sqlite3", dsn)
check(err)
defer db.Close()
rows, err := db.Query("SELECT * FROM sysconfig")
check(err)
defer rows.Close()
for rows.Next() {
var name string
var val string
err = rows.Scan(&name, &val)
if err != nil {
log.Fatal(err)
}
fmt.Printf("[%s]: %s\n", name, val)
}
err = rows.Err()
check(err)
}