cmd/ofx: Add -dryrun

This commit is contained in:
Aaron Lindsay 2020-12-07 13:37:43 -05:00
parent 4c7c48cab7
commit 56ca46714b
3 changed files with 18 additions and 0 deletions

View File

@ -23,6 +23,7 @@ func (c *command) usage() {
var serverURL, username, password, org, fid, appID, appVer, ofxVersion, clientUID string var serverURL, username, password, org, fid, appID, appVer, ofxVersion, clientUID string
var noIndentRequests bool var noIndentRequests bool
var carriageReturn bool var carriageReturn bool
var dryrun bool
func defineServerFlags(f *flag.FlagSet) { 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(&serverURL, "url", "", "Financial institution's OFX Server URL (see ofxhome.com if you don't know it)")
@ -36,6 +37,7 @@ func defineServerFlags(f *flag.FlagSet) {
f.StringVar(&clientUID, "clientuid", "", "Client UID (only required by a few FIs, like Chase)") 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(&noIndentRequests, "noindent", false, "Don't indent OFX requests")
f.BoolVar(&carriageReturn, "carriagereturn", false, "Use carriage return as line separator") f.BoolVar(&carriageReturn, "carriagereturn", false, "Use carriage return as line separator")
f.BoolVar(&dryrun, "dryrun", false, "Don't send request - print content of request instead")
} }
func checkServerFlags() bool { func checkServerFlags() bool {

View File

@ -54,6 +54,11 @@ func downloadProfile() {
query.Prof = append(query.Prof, &profileRequest) query.Prof = append(query.Prof, &profileRequest)
if dryrun {
printRequest(client, query)
return
}
response, err := client.RequestNoParse(query) response, err := client.RequestNoParse(query)
if err != nil { if err != nil {
fmt.Println("Error requesting FI profile:", err) fmt.Println("Error requesting FI profile:", err)

View File

@ -31,3 +31,14 @@ func newRequest() (ofxgo.Client, *ofxgo.Request) {
return client, &query return client, &query
} }
func printRequest(c ofxgo.Client, r *ofxgo.Request) {
r.SetClientFields(c)
b, err := r.Marshal()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(b)
}