forked from sacloud/usacloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bill_csv_args.go
44 lines (35 loc) · 811 Bytes
/
bill_csv_args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package completion
import (
"fmt"
"github.com/sacloud/libsacloud/sacloud"
"github.com/sacloud/usacloud/command"
"github.com/sacloud/usacloud/command/params"
"strings"
)
func BillCsvCompleteArgs(ctx command.Context, params *params.CsvBillParam, cur, prev, commandName string) {
if !command.GlobalOption.Valid {
return
}
client := ctx.GetAPIClient()
finder := client.GetBillAPI()
// auth-status
auth, err := client.GetAuthStatusAPI().Read()
if err != nil {
return
}
accountID := sacloud.NewResourceByStringID(auth.Account.ID).ID
if accountID == 0 {
return
}
if !strings.Contains(auth.ExternalPermission, "bill") {
return
}
// call Find()
res, err := finder.ByContract(accountID)
if err != nil {
return
}
for i := range res.Bills {
fmt.Println(res.Bills[i].BillID)
}
}