use clap::{Args, Subcommand};
use rbxcloud::rbx::{types::RobloxUserId, v2::Client};
#[derive(Debug, Subcommand)]
pub enum InventoryCommands {
List {
#[clap(short, long, value_parser)]
user_id: u64,
#[clap(short, long, value_parser, default_value_t = false)]
pretty: bool,
#[clap(short, long, value_parser)]
max_page_size: Option<u32>,
#[clap(short = 'n', long, value_parser)]
page_token: Option<String>,
#[clap(short, long, value_parser)]
filter: Option<String>,
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
api_key: String,
},
}
#[derive(Debug, Args)]
pub struct Inventory {
#[clap(subcommand)]
command: InventoryCommands,
}
impl Inventory {
pub async fn run(self) -> anyhow::Result<Option<String>> {
match self.command {
InventoryCommands::List {
user_id,
pretty,
max_page_size,
page_token,
filter,
api_key,
} => {
let client = Client::new(&api_key);
let inventory = client.inventory();
let res = inventory
.list_inventory_items(RobloxUserId(user_id), max_page_size, page_token, filter)
.await;
match res {
Ok(data) => {
let r = if pretty {
serde_json::to_string_pretty(&data)?
} else {
serde_json::to_string(&data)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}
}
}
}