-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (57 loc) · 1.28 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"flag"
"fmt"
"log"
"os"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
func parseArgs(path *string, name *string, column *int, hasColumnNames *bool) {
flag.Usage = func() {
fmt.Println("")
fmt.Printf("Usage: %s [OPTIONS] -f csv_file\n", os.Args[0])
flag.PrintDefaults()
fmt.Println("")
fmt.Printf("Version: %s\n", version)
fmt.Printf("Commit: %s\n", commit)
fmt.Printf("Date: %s\n", date)
fmt.Println("")
}
flag.StringVar(path, "f", "", "File path")
flag.StringVar(name, "n", "", "Column name. Implies -1 flag")
flag.IntVar(column, "c", 0, "Column position. Negative numbers are allowed")
flag.BoolVar(hasColumnNames, "1", false, "The first line has the names of the columns")
flag.Parse()
if *path == "" {
fmt.Fprintf(os.Stderr, "Must supply a CSV file\n\n")
flag.Usage()
os.Exit(1)
}
if *name != "" {
*hasColumnNames = true
}
}
func main() {
var path string
var name string
var column int
var hasColumnNames bool
parseArgs(&path, &name, &column, &hasColumnNames)
reader := NewReader(path, hasColumnNames)
if name != "" {
check(reader.SelectNamedColumn(name))
} else {
reader.SelectColumn(column)
}
tui := NewTUI(reader)
check(tui.Run())
}
func check(err error) {
if err != nil {
log.Fatal(err)
}
}