1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-14 01:00:06 -05:00
ofxgo/cmd/ofx/command.go
Aaron Lindsay e1a72fcd54 Replace github.com/howeyc/gopass with golang.org/x/term
gopass is no longer maintained, and the suggested replacement for
getting passwords from terminals is x/term.
2021-10-17 21:20:04 -04:00

69 lines
2.3 KiB
Go

package main
import (
"flag"
"fmt"
"golang.org/x/term"
"os"
)
type command struct {
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)
}
func (c *command) usage() {
fmt.Printf("Usage of %s:\n", c.Name)
c.Flags.PrintDefaults()
}
// flags common to all server transactions
var serverURL, username, password, org, fid, appID, appVer, ofxVersion, clientUID string
var noIndentRequests bool
var carriageReturn bool
var dryrun bool
var userAgent string
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")
f.StringVar(&appID, "appid", "QWIN", "'APPID' to pretend to be")
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")
f.BoolVar(&carriageReturn, "carriagereturn", false, "Use carriage return as line separator")
f.StringVar(&userAgent, "useragent", "", "Use string as User-Agent header when sending request")
f.BoolVar(&dryrun, "dryrun", false, "Don't send request - print content of request instead")
}
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 := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Printf("Error reading password: %s\n", err)
ret = false
} else {
password = string(pass)
}
}
return ret
}