mod commands;
mod output;
use clap::{Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(name = "szamlazz", version, about)]
struct Cli {
#[arg(
long,
env = "SZAMLAZZ_AGENT_KEY",
global = true,
hide_env_values = true
)]
agent_key: Option<String>,
#[arg(long, env = "SZAMLAZZ_ENDPOINT", global = true, hide = true)]
endpoint: Option<String>,
#[arg(long, global = true)]
json: bool,
#[command(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
#[command(subcommand)]
Invoice(commands::invoice::InvoiceCommand),
#[command(subcommand)]
Payment(commands::payment::PaymentCommand),
#[command(subcommand)]
Proforma(commands::proforma::ProformaCommand),
#[command(subcommand)]
Receipt(commands::receipt::ReceiptCommand),
Taxpayer(commands::taxpayer::TaxpayerArgs),
Listen(commands::listen::ListenArgs),
}
fn client(cli: &Cli) -> anyhow::Result<szamlazz_agent::Client> {
let key = cli.agent_key.clone().ok_or_else(|| {
anyhow::anyhow!("no agent key: pass --agent-key or set SZAMLAZZ_AGENT_KEY")
})?;
let mut builder =
szamlazz_agent::Client::builder().credentials(szamlazz_agent::Credentials::agent_key(key));
if let Some(endpoint) = &cli.endpoint {
builder = builder.endpoint(endpoint.clone());
}
Ok(builder.build()?)
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
match &cli.command {
Command::Invoice(command) => commands::invoice::run(&cli, command).await,
Command::Payment(command) => commands::payment::run(&cli, command).await,
Command::Proforma(command) => commands::proforma::run(&cli, command).await,
Command::Receipt(command) => commands::receipt::run(&cli, command).await,
Command::Taxpayer(args) => commands::taxpayer::run(&cli, args).await,
Command::Listen(args) => commands::listen::run(args).await,
}
}