Skip to main content

cflare/commands/
accounts.rs

1use cloudflare::endpoints::account::{
2    Account,
3    list_accounts::ListAccountsParams,
4    ListAccounts,
5};
6use cloudflare::framework::{
7    apiclient::ApiClient,
8    HttpApiClient,
9    OrderDirection,
10};
11use tabular::Row;
12
13use crate::commands::table_from_cols;
14
15pub fn list(api: &HttpApiClient, page: u32, limit: u32) {
16    let response = api.request(&ListAccounts {
17        params: Some(ListAccountsParams {
18            page: Some(page),
19            per_page: Some(limit),
20            direction: Some(OrderDirection::Ascending),
21        })
22    });
23
24    match response {
25        Ok(success) => {
26            let list: Vec<Account> = success.result;
27            let columns = vec![
28                "ID",
29                "NAME"
30            ];
31            let mut table = table_from_cols(columns);
32
33            for acc in list {
34                table.add_row(Row::new()
35                    .with_cell(acc.id)
36                    .with_cell(acc.name));
37            }
38            print!("{}", table);
39        }
40        Err(e) => println!("{:?}", e)
41    }
42}