-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
91 lines (81 loc) · 1.63 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"fmt"
"log"
"os"
"runtime"
"runtime/pprof"
"strings"
"text/tabwriter"
"github.com/TuftsBCB/tools/util"
)
var commands = []*command{
cmdMkBowDb,
cmdMkPaired,
cmdMkSeqHMM,
cmdMkSeqProfile,
cmdMkStructure,
cmdMkWeighted,
cmdPairdist,
cmdSearch,
cmdVectors,
cmdViewLib,
}
func usage() {
log.Println("flib is a tool for creating and using fragment libraries.\n")
log.Println("Usage:\n\n flib {command} [flags] [arguments]\n")
log.Println("Use 'flib help {command}' for more details on {command}.\n")
log.Println("A list of all available commands:\n")
tabw := tabwriter.NewWriter(os.Stderr, 0, 0, 4, ' ', 0)
for _, c := range commands {
fmt.Fprintf(tabw, " %s\t%s\n", c.name, c.shortHelp)
}
tabw.Flush()
log.Println("")
os.Exit(1)
}
func main() {
var cmd string
var help bool
if len(os.Args) < 2 {
usage()
} else if strings.TrimLeft(os.Args[1], "-") == "help" {
if len(os.Args) < 3 {
usage()
} else {
cmd = os.Args[2]
help = true
}
} else {
cmd = os.Args[1]
}
for _, c := range commands {
if c.name == cmd {
c.setCommonFlags()
if c.addFlags != nil {
c.addFlags(c)
}
if help {
c.showHelp()
} else {
c.flags.Usage = c.showUsage
c.flags.Parse(os.Args[2:])
if flagCpu < 1 {
flagCpu = 1
}
runtime.GOMAXPROCS(flagCpu)
if len(flagCpuProfile) > 0 {
f := util.CreateFile(flagCpuProfile)
pprof.StartCPUProfile(f)
defer f.Close()
defer pprof.StopCPUProfile()
}
c.run(c)
return
}
}
}
log.Printf("Unknown command '%s'. Run 'flib help' for a list of "+
"available commands.", cmd)
os.Exit(1)
}