Skip to content

Commit 16eb284

Browse files
committed
Add instructions for configuration + some error messages
1 parent 4b0fc08 commit 16eb284

File tree

2 files changed

+111
-3
lines changed

2 files changed

+111
-3
lines changed

README.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
1-
# plaid-cli
1+
# plaid-cli 🤑
22

33
> Link accounts and get transactions from the command line.
44
5+
plaid-cli is a CLI tool for working with the Plaid API.
6+
7+
You can use plaid-cli to link bank accounts and pull transactions in multiple
8+
output formats from the comfort of the command line.
9+
10+
## Configuration
11+
12+
To get started, you'll need Plaid API credentials, which you can get by visiting
13+
https://dashboard.plaid.com/team/keys after signing up for free.
14+
15+
plaid-cli will look at the following environment variables for API credentials:
16+
17+
```sh
18+
PLAID_CLIENT_ID=<client id>
19+
PLAID_PUBLIC_KEY=<public key>
20+
PLAID_SECRET=<devlopment secret>
21+
PLAID_ENVIRONMENT=development
22+
```
23+
24+
I recommend setting and exporting these on shell startup.
25+
26+
API credentials can also be specified using a config file located at
27+
~/.plaid-cli/config.toml:
28+
29+
```toml
30+
[plaid]
31+
client_id = "<client id>"
32+
public_key = "<public key>"
33+
secret = "<development secret>"
34+
environment = "development"
35+
```
36+
37+
After setting those API credentials, plaid-cli is ready to use!
38+
You'll probably want to run 'plaid-cli link' next.
39+
540
## Usage
641

742
<pre>

main.go

+75-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"log"
1010
"net/http"
11+
"os"
1112
"os/user"
1213
"path/filepath"
1314
"regexp"
@@ -44,13 +45,28 @@ func main() {
4445
}
4546
}
4647

48+
viper.SetEnvPrefix("")
49+
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
4750
viper.AutomaticEnv()
4851

52+
viper.SetDefault("plaid.environment", "development")
53+
plaidEnvStr := strings.ToLower(viper.GetString("plaid.environment"))
54+
55+
var plaidEnv plaid.Environment
56+
switch plaidEnvStr {
57+
case "development":
58+
plaidEnv = plaid.Development
59+
case "production":
60+
plaidEnv = plaid.Production
61+
default:
62+
log.Fatalln("Invalid plaid environment. Valid plaid environments are 'development' or 'production'.")
63+
}
64+
4965
opts := plaid.ClientOptions{
5066
viper.GetString("plaid.client_id"),
5167
viper.GetString("plaid.secret"),
5268
viper.GetString("plaid.public_key"),
53-
plaid.Development,
69+
plaidEnv,
5470
&http.Client{},
5571
}
5672

@@ -286,13 +302,70 @@ func main() {
286302
transactionsCommand.Flags().StringVarP(&outputFormat, "output-format", "o", "json", "Output format")
287303
transactionsCommand.Flags().StringVarP(&accountID, "account-id", "a", "", "Fetch transactions for this account ID only.")
288304

289-
rootCommand := &cobra.Command{Use: "plaid-cli"}
305+
rootCommand := &cobra.Command{
306+
Use: "plaid-cli",
307+
Short: "Link bank accounts and get transactions from the command line.",
308+
Long: `plaid-cli 🤑
309+
310+
plaid-cli is a CLI tool for working with the Plaid API.
311+
312+
You can use plaid-cli to link bank accounts and pull transactions in multiple
313+
output formats from the comfort of the command line.
314+
315+
Configuration:
316+
To get started, you'll need Plaid API credentials, which you can get by visiting
317+
https://dashboard.plaid.com/team/keys after signing up for free.
318+
319+
plaid-cli will look at the following environment variables for API credentials:
320+
321+
PLAID_CLIENT_ID=<client id>
322+
PLAID_PUBLIC_KEY=<public key>
323+
PLAID_SECRET=<devlopment secret>
324+
PLAID_ENVIRONMENT=development
325+
326+
I recommend setting and exporting these on shell startup.
327+
328+
API credentials can also be specified using a config file located at
329+
~/.plaid-cli/config.toml:
330+
331+
[plaid]
332+
client_id = "<client id>"
333+
public_key = "<public key>"
334+
secret = "<development secret>"
335+
environment = "development"
336+
337+
After setting those API credentials, plaid-cli is ready to use!
338+
You'll probably want to run 'plaid-cli link' next.
339+
340+
Please see the README (https://github.com/landakram/plaid-cli/blob/master/README.md)
341+
for more detailed usage instructions.
342+
343+
Made by @landakram.
344+
`,
345+
}
290346
rootCommand.AddCommand(linkCommand)
291347
rootCommand.AddCommand(tokensCommand)
292348
rootCommand.AddCommand(aliasCommand)
293349
rootCommand.AddCommand(aliasesCommand)
294350
rootCommand.AddCommand(accountsCommand)
295351
rootCommand.AddCommand(transactionsCommand)
352+
353+
if !viper.IsSet("plaid.client_id") {
354+
log.Println("⚠️ PLAID_CLIENT_ID not set. Please see the configuration instructions below.")
355+
rootCommand.Help()
356+
os.Exit(1)
357+
}
358+
if !viper.IsSet("plaid.secret") {
359+
log.Println("⚠️ PLAID_SECRET not set. Please see the configuration instructions below.")
360+
rootCommand.Help()
361+
os.Exit(1)
362+
}
363+
if !viper.IsSet("plaid.public_key") {
364+
log.Println("⚠️ PLAID_PUBLIC_KEY not set. Please see the configuration instructions below.")
365+
rootCommand.Help()
366+
os.Exit(1)
367+
}
368+
296369
rootCommand.Execute()
297370
}
298371

0 commit comments

Comments
 (0)