diff --git a/main.go b/main.go index 3a38b80..d7f081d 100644 --- a/main.go +++ b/main.go @@ -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() }