| 1 |
// Copyright © 2015 Michael Wagner <[email protected]> |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
package main |
| 16 |
|
| 17 |
import ( |
| 18 |
"fmt" |
| 19 |
"os" |
| 20 |
|
| 21 |
"github.com/mitch000001/go-hbci/domain" |
| 22 |
"github.com/mitch000001/go-hbci/iban" |
| 23 |
"github.com/spf13/cobra" |
| 24 |
) |
| 25 |
|
| 26 |
var balanceAccount string |
| 27 |
|
| 28 |
// balancesCmd represents the balances command |
| 29 |
var balancesCmd = &cobra.Command{ |
| 30 |
Use: "balances", |
| 31 |
Short: "Fetches balances for a specific account", |
| 32 |
Long: `This command allows to fetch balances for a specific account. By |
| 33 |
default it will fetch the balance for the account used to authenticate. For example: |
| 34 |
|
| 35 |
banking balances --accountID=123456789 |
| 36 |
|
| 37 |
will fetch the balance for account 123456789.`, |
| 38 |
Run: func(cmd *cobra.Command, args []string) { |
| 39 |
if balanceAccount == "" { |
| 40 |
balanceAccount = clientConfig.AccountID |
| 41 |
} |
| 42 |
i, err := iban.NewGerman(clientConfig.BankID, balanceAccount) |
| 43 |
if err != nil { |
| 44 |
fmt.Println(err) |
| 45 |
os.Exit(1) |
| 46 |
} |
| 47 |
account = domain.InternationalAccountConnection{ |
| 48 |
IBAN: string(i), |
| 49 |
AccountID: balanceAccount, |
| 50 |
BankID: domain.BankID{CountryCode: 280, ID: clientConfig.BankID}, |
| 51 |
} |
| 52 |
balances, err := hbciClient.AccountBalances(account.ToAccountConnection(), true) |
| 53 |
|
| 54 |
if err != nil { |
| 55 |
fmt.Println(err) |
| 56 |
os.Exit(1) |
| 57 |
} |
| 58 |
|
| 59 |
fmt.Printf(domain.AccountBalances(balances).String()) |
| 60 |
}, |
| 61 |
} |
| 62 |
|
| 63 |
func init() { |
| 64 |
rootCmd.AddCommand(balancesCmd) |
| 65 |
|
| 66 |
balancesCmd.Flags().StringVar( |
| 67 |
&balanceAccount, "accountID", "", |
| 68 |
"the accountID to fetch balance for (defaults to the UserID)", |
| 69 |
) |
| 70 |
} |