Adds help messaging via flag lib
This commit is contained in:
parent
3972b3914e
commit
0f252e600b
38
main.go
38
main.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -179,15 +180,30 @@ func handleSignals(c <-chan os.Signal) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func printHelp() {
|
||||||
// watch for signals, send them to be handled
|
header := `tally - spreadsheets
|
||||||
c := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(c, syscall.SIGTSTP, syscall.SIGCONT, syscall.SIGINT)
|
|
||||||
go handleSignals(c)
|
|
||||||
|
|
||||||
args := os.Args
|
Syntax: tally [filepath]
|
||||||
if len(args) > 1 {
|
|
||||||
path := ExpandedAbsFilepath(args[1])
|
Examples: tally
|
||||||
|
tally -h
|
||||||
|
tally ./my-tally-spreadsheet.tss
|
||||||
|
tally ./my-cool-csv.csv
|
||||||
|
tally ./my-cool-tsv.tsv
|
||||||
|
|
||||||
|
filepath should be a path to a file that already exists. To create a new file, simply run tally with no arguments and then save the file however you like.
|
||||||
|
`
|
||||||
|
_, _ = fmt.Fprintf(os.Stdout, header)
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Usage = printHelp
|
||||||
|
flag.Parse()
|
||||||
|
args := flag.Args()
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
path := ExpandedAbsFilepath(args[0])
|
||||||
ext := strings.ToLower(filepath.Ext(path))
|
ext := strings.ToLower(filepath.Ext(path))
|
||||||
switch ext {
|
switch ext {
|
||||||
case ".tss":
|
case ".tss":
|
||||||
|
@ -204,5 +220,11 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
wb = makeWorkbook("blank.tss")
|
wb = makeWorkbook("blank.tss")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// watch for signals, send them to be handled
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, syscall.SIGTSTP, syscall.SIGCONT, syscall.SIGINT)
|
||||||
|
go handleSignals(c)
|
||||||
|
|
||||||
wb.Run()
|
wb.Run()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue