Force CLI is open-sourced. Anyone can fork the repo.
File query.go is responsible for querying. It could be used as:
force query "select Id, Name, Account.Name From Contact"
But we want to pass file, e.g.:
force query file.txt
Line 47 joining query into single string and then passed to force.query method
soql := strings.Join(args, " ")
force.Query(fmt.Sprintf("%s", soql)
Lets try to read args[0] as file and assign it to soql string. Add before line 47 next code:
if _, err := os.Stat(args[0]); err == nil {
var qyery []byte
qyery, err = ioutil.ReadFile(args[0])
args[0] = string(qyery)
}
Add libraries "io/ioutil" and"os"
to import:
import (
"fmt"
"strings"
)
That's it. You could compile it and use.
C:\Projects\Go\bin>echo select name, stagename from opportunity limit 2 > file.txt
C:\Projects\Go\bin>force query file.txt --format:csv
"Name","StageName"
"Jefferson","Prospecting"
"Boston","Prospecting"
Prerequisites from link and Heroku github:
- Have Git installed on your computer.
- Make sure that you have The Go Programming Language installed. To make things simple, use the default installation path at `C:\Go`
- Make sure that you have Mercurial installed.
- Ensure the Go binaries (found in C:\Go\bin) are in your Path system environment variables.
- Create `C:\Projects\Go` with three folders: `bin/,pkg/,src/`
- Set the variable name to GOPATH and value to your Go workspace path (e.g. C:\Projects\Go)
# download the source and all dependencies
$ go get -u github.com/heroku/force
$ cd %GOPATH%/src/github.com/heroku/force
# provide your changes
# to compile and test modifications:
$ go get .
$ cd C:\Projects\Go\bin
$ force