use crate::cmds::accounts::get_current_account;
use clap::Subcommand;
use ordinary_api::client::OrdinaryApiClient;
use std::error::Error;
#[derive(Subcommand)]
pub enum Assets {
Put {
#[arg(short, long)]
name: Option<String>,
},
}
impl Assets {
pub async fn handle(
&self,
host_domain: Option<&str>,
accept_invalid_certs: bool,
project: &str,
insecure: bool,
) -> Result<(), Box<dyn Error>> {
let account = get_current_account(insecure)?;
let client = OrdinaryApiClient::new(
&account.host,
&account.name,
host_domain,
accept_invalid_certs,
);
match self {
Self::Put { name } => {
if let Some(name) = name {
client.write(project, name).await?;
} else {
client.write_all(project).await?;
}
}
}
Ok(())
}
}