1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-14 09:10:05 -05:00
ofxgo/cmd/ofx/main.go

83 lines
1.4 KiB
Go
Raw Normal View History

2017-03-22 20:29:08 -04:00
package main
import (
"fmt"
"os"
"strconv"
)
2017-04-16 20:50:06 -04:00
var commands = []command{
2020-11-25 14:31:37 -05:00
profileDownloadCommand,
2017-03-22 20:29:08 -04:00
getAccountsCommand,
downloadCommand,
ccDownloadCommand,
invDownloadCommand,
bankTransactionsCommand,
ccTransactionsCommand,
invTransactionsCommand,
detectSettingsCommand,
2017-03-22 20:29:08 -04:00
}
func usage() {
fmt.Println(`The ofxgo command-line client provides a simple interface to
query, parse, and display financial data via the OFX specification.
Usage:
ofx command [arguments]
The commands are:`)
maxlen := 0
for _, cmd := range commands {
if len(cmd.Name) > maxlen {
maxlen = len(cmd.Name)
}
}
formatString := " %-" + strconv.Itoa(maxlen) + "s %s\n"
for _, cmd := range commands {
fmt.Printf(formatString, cmd.Name, cmd.Description)
}
}
2017-04-16 20:50:06 -04:00
func runCmd(c *command) {
2017-03-22 20:29:08 -04:00
err := c.Flags.Parse(os.Args[2:])
if err != nil {
fmt.Printf("Error parsing flags: %s\n", err)
2017-04-16 20:50:06 -04:00
c.usage()
2017-03-22 20:29:08 -04:00
os.Exit(1)
}
if !c.CheckFlags() {
fmt.Println()
2017-04-16 20:50:06 -04:00
c.usage()
2017-03-22 20:29:08 -04:00
os.Exit(1)
}
c.Do()
}
func main() {
if len(os.Args) < 2 {
2017-03-28 19:47:17 -04:00
fmt.Printf("Error: Please supply a sub-command. Usage:\n\n")
2017-03-22 20:29:08 -04:00
usage()
os.Exit(1)
}
cmdName := os.Args[1]
for _, cmd := range commands {
if cmd.Name == cmdName {
runCmd(&cmd)
os.Exit(0)
}
}
switch cmdName {
case "-h", "-help", "--help", "help":
usage()
default:
fmt.Println("Error: Invalid sub-command. Usage:")
usage()
os.Exit(1)
}
}