Skip to content

Commit

Permalink
Merge pull request #444 from cwarden/display-logs-then-fetch-more
Browse files Browse the repository at this point in the history
Fetch All Logs
  • Loading branch information
dcarroll authored Sep 29, 2017
2 parents 9854a5d + dbbaf6d commit b396970
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion command/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func getLog(cmd *Command, args []string) {
if err != nil {
ErrorAndExit(err.Error())
}
DisplayForceRecords(records)
force.DisplayAllForceRecords(records)
} else if args[0] == "delete" {
if len(args) != 2 {
ErrorAndExit("You need to provide the id of a debug log to delete.")
Expand Down
15 changes: 15 additions & 0 deletions lib/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ func DisplayForceRecordsf(records []ForceRecord, format string) {
}
}

func (f *Force) DisplayAllForceRecords(result ForceQueryResult) {
currentResult := result
var err error
for {
DisplayForceRecords(currentResult)
if currentResult.Done {
return
}
currentResult, err = f.getForceResult(currentResult.NextRecordsUrl)
if err != nil {
ErrorAndExit(err.Error())
}
}
}

func DisplayForceRecords(result ForceQueryResult) {
if len(result.Records) > 0 {
fmt.Print(RenderForceRecords(result.Records))
Expand Down
9 changes: 9 additions & 0 deletions lib/force.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,15 @@ func (f *Force) PatchREST(url string, content string) (result string, err error)
return
}

func (f *Force) getForceResult(url string) (results ForceQueryResult, err error) {
body, err := f.httpGet(fmt.Sprintf("%s%s", f.Credentials.InstanceUrl, url))
if err != nil {
return
}
json.Unmarshal(body, &results)
return
}

func (f *Force) httpGet(url string) (body []byte, err error) {
body, err = f.httpGetRequest(url, "Authorization", fmt.Sprintf("Bearer %s", f.Credentials.AccessToken))
if err == SessionExpiredError {
Expand Down

0 comments on commit b396970

Please sign in to comment.