Skip to content

Commit

Permalink
cmd/ofx: Add -dryrun
Browse files Browse the repository at this point in the history
  • Loading branch information
aclindsa committed Dec 7, 2020
1 parent 302ec2e commit 423385f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/ofx/command.go
Expand Up @@ -23,6 +23,7 @@ func (c *command) usage() {
var serverURL, username, password, org, fid, appID, appVer, ofxVersion, clientUID string
var noIndentRequests bool
var carriageReturn bool
var dryrun 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)")
Expand All @@ -36,6 +37,7 @@ func defineServerFlags(f *flag.FlagSet) {
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.BoolVar(&dryrun, "dryrun", false, "Don't send request - print content of request instead")
}

func checkServerFlags() bool {
Expand Down
5 changes: 5 additions & 0 deletions cmd/ofx/profiledownload.go
Expand Up @@ -54,6 +54,11 @@ func downloadProfile() {

query.Prof = append(query.Prof, &profileRequest)

if dryrun {
printRequest(client, query)
return
}

response, err := client.RequestNoParse(query)
if err != nil {
fmt.Println("Error requesting FI profile:", err)
Expand Down
11 changes: 11 additions & 0 deletions cmd/ofx/util.go
Expand Up @@ -31,3 +31,14 @@ func newRequest() (ofxgo.Client, *ofxgo.Request) {

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)
}

0 comments on commit 423385f

Please sign in to comment.