|
8 | 8 | "fmt"
|
9 | 9 | "log"
|
10 | 10 | "net/http"
|
| 11 | + "os" |
11 | 12 | "os/user"
|
12 | 13 | "path/filepath"
|
13 | 14 | "regexp"
|
@@ -44,13 +45,28 @@ func main() {
|
44 | 45 | }
|
45 | 46 | }
|
46 | 47 |
|
| 48 | + viper.SetEnvPrefix("") |
| 49 | + viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_")) |
47 | 50 | viper.AutomaticEnv()
|
48 | 51 |
|
| 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 | + |
49 | 65 | opts := plaid.ClientOptions{
|
50 | 66 | viper.GetString("plaid.client_id"),
|
51 | 67 | viper.GetString("plaid.secret"),
|
52 | 68 | viper.GetString("plaid.public_key"),
|
53 |
| - plaid.Development, |
| 69 | + plaidEnv, |
54 | 70 | &http.Client{},
|
55 | 71 | }
|
56 | 72 |
|
@@ -286,13 +302,70 @@ func main() {
|
286 | 302 | transactionsCommand.Flags().StringVarP(&outputFormat, "output-format", "o", "json", "Output format")
|
287 | 303 | transactionsCommand.Flags().StringVarP(&accountID, "account-id", "a", "", "Fetch transactions for this account ID only.")
|
288 | 304 |
|
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 | + } |
290 | 346 | rootCommand.AddCommand(linkCommand)
|
291 | 347 | rootCommand.AddCommand(tokensCommand)
|
292 | 348 | rootCommand.AddCommand(aliasCommand)
|
293 | 349 | rootCommand.AddCommand(aliasesCommand)
|
294 | 350 | rootCommand.AddCommand(accountsCommand)
|
295 | 351 | 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 | + |
296 | 369 | rootCommand.Execute()
|
297 | 370 | }
|
298 | 371 |
|
|
0 commit comments