Adds help messaging via flag lib

This commit is contained in:
sloum 2021-03-18 12:46:26 -07:00
parent 3972b3914e
commit 0f252e600b
1 changed files with 30 additions and 8 deletions

38
main.go
View File

@ -2,6 +2,7 @@ package main
import (
"bufio"
"flag"
"fmt"
"os"
"os/signal"
@ -179,15 +180,30 @@ func handleSignals(c <-chan os.Signal) {
}
}
func main() {
// 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)
func printHelp() {
header := `tally - spreadsheets
args := os.Args
if len(args) > 1 {
path := ExpandedAbsFilepath(args[1])
Syntax: tally [filepath]
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))
switch ext {
case ".tss":
@ -204,5 +220,11 @@ func main() {
} else {
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()
}