1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-25 04:20:05 -05:00
ofxgo/cmd/ofx/command.go

62 lines
1.9 KiB
Go
Raw Normal View History

2017-03-22 20:29:08 -04:00
package main
import (
"flag"
"fmt"
"github.com/howeyc/gopass"
)
2017-04-16 20:50:06 -04:00
type command struct {
2017-03-22 20:29:08 -04:00
Name string
Description string
Flags *flag.FlagSet
CheckFlags func() bool // Check the flag values after they're parsed, printing errors and returning false if they're incorrect
Do func() // Run the command (only called if CheckFlags returns true)
}
2017-04-16 20:50:06 -04:00
func (c *command) usage() {
2017-03-22 20:29:08 -04:00
fmt.Printf("Usage of %s:\n", c.Name)
c.Flags.PrintDefaults()
}
// flags common to all server transactions
2017-04-12 21:40:42 -04:00
var serverURL, username, password, org, fid, appID, appVer, ofxVersion, clientUID string
2017-03-22 20:29:08 -04:00
var noIndentRequests bool
func defineServerFlags(f *flag.FlagSet) {
f.StringVar(&serverURL, "url", "", "Financial institution's OFX Server URL (see ofxhome.com if you don't know it)")
f.StringVar(&username, "username", "", "Your username at financial institution")
f.StringVar(&password, "password", "", "Your password at financial institution")
f.StringVar(&org, "org", "", "'ORG' for your financial institution")
f.StringVar(&fid, "fid", "", "'FID' for your financial institution")
2017-04-12 21:40:42 -04:00
f.StringVar(&appID, "appid", "QWIN", "'APPID' to pretend to be")
2017-03-22 20:29:08 -04:00
f.StringVar(&appVer, "appver", "2400", "'APPVER' to pretend to be")
f.StringVar(&ofxVersion, "ofxversion", "203", "OFX version to use")
f.StringVar(&clientUID, "clientuid", "", "Client UID (only required by a few FIs, like Chase)")
f.BoolVar(&noIndentRequests, "noindent", false, "Don't indent OFX requests")
}
func checkServerFlags() bool {
var ret bool = true
if len(serverURL) == 0 {
fmt.Println("Error: Server URL empty")
ret = false
}
if len(username) == 0 {
fmt.Println("Error: Username empty")
ret = false
}
if ret && len(password) == 0 {
fmt.Printf("Password for %s: ", username)
pass, err := gopass.GetPasswd()
if err != nil {
fmt.Printf("Error reading password: %s\n", err)
ret = false
} else {
password = string(pass)
}
}
return ret
}