pub mod accounts;
pub mod admin;
pub mod check;
pub mod contacts;
pub mod documents;
pub mod init;
pub mod invoices;
pub mod projects;
pub mod upload;
pub mod vat;
use clap::{Parser, Subcommand};
use crate::client::accounting::AccountingClient;
use crate::config::{AdminEntry, Config};
use crate::error::YukiError;
pub async fn setup_domain(
config: &Config,
admin: Option<&str>,
) -> Result<(AccountingClient, AdminEntry), YukiError> {
let entry = config.resolve_admin(admin)?;
let mut client = AccountingClient::new();
client.authenticate(&config.api_key).await?;
client.set_current_domain(&entry.domain_id).await?;
Ok((client, entry))
}
#[derive(Parser)]
#[command(
name = "yuki",
version,
about = "CLI client for the Yuki bookkeeping API"
)]
pub struct Cli {
#[arg(long = "admin", global = true)]
pub admin: Option<String>,
#[arg(long, global = true)]
pub format: Option<String>,
#[arg(long, short, global = true)]
pub quiet: bool,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
Init {
#[arg(long)]
api_key: Option<String>,
#[arg(long)]
default_admin: Option<String>,
},
Admin {
#[command(subcommand)]
command: AdminCommands,
},
Invoices {
#[command(subcommand)]
command: InvoiceCommands,
},
Documents {
#[command(subcommand)]
command: DocumentCommands,
},
Contacts {
#[command(subcommand)]
command: ContactCommands,
},
Accounts {
#[command(subcommand)]
command: AccountCommands,
},
Vat {
#[command(subcommand)]
command: VatCommands,
},
Projects {
#[command(subcommand)]
command: ProjectCommands,
},
Check {
#[command(subcommand)]
command: CheckCommands,
},
Upload {
#[command(subcommand)]
command: UploadCommands,
},
Completions {
shell: clap_complete::Shell,
},
Schema,
}
#[derive(Subcommand)]
pub enum AdminCommands {
List,
Switch {
name: String,
},
}
#[derive(Subcommand)]
pub enum InvoiceCommands {
List {
#[arg(long)]
period: Option<String>,
#[arg(long)]
invoice_type: Option<String>,
},
Show {
id: String,
},
Document {
id: String,
},
}
#[derive(Subcommand)]
pub enum DocumentCommands {
List {
#[arg(long)]
folder: Option<String>,
#[arg(long)]
doc_type: Option<String>,
},
Search {
query: String,
},
Exists {
#[arg(long)]
amount: f64,
#[arg(long)]
date: String,
#[arg(long)]
contact: Option<String>,
},
}
#[derive(Subcommand)]
pub enum ContactCommands {
Search {
query: String,
},
List {
#[arg(long)]
contact_type: Option<String>,
},
}
#[derive(Subcommand)]
pub enum AccountCommands {
Balance {
#[arg(long)]
account: Option<String>,
#[arg(long)]
period: Option<String>,
},
Transactions {
#[arg(long)]
account: Option<String>,
#[arg(long)]
period: Option<String>,
},
Scheme,
Revenue {
#[arg(long)]
period: Option<String>,
},
StartBalance {
#[arg(long)]
year: Option<String>,
},
}
#[derive(Subcommand)]
pub enum ProjectCommands {
List,
Balance {
project: String,
#[arg(long)]
account: Option<String>,
#[arg(long)]
period: Option<String>,
},
}
#[derive(Subcommand)]
pub enum VatCommands {
Returns {
year: Option<String>,
},
Codes,
}
#[derive(Subcommand)]
pub enum CheckCommands {
Btw {
period: Option<String>,
},
Unmatched {
#[arg(long)]
period: Option<String>,
#[arg(long, default_value = "11001")]
bank_account: String,
},
Outstanding {
reference: String,
},
}
#[derive(Subcommand)]
pub enum UploadCommands {
File {
file: String,
#[arg(long, default_value = "uitzoeken")]
folder: String,
#[arg(long)]
amount: Option<f64>,
#[arg(long)]
category: Option<String>,
#[arg(long = "payment-method")]
payment_method: Option<String>,
#[arg(long)]
project: Option<String>,
#[arg(long)]
remarks: Option<String>,
#[arg(long, default_value = "EUR")]
currency: String,
},
Categories,
PaymentMethods,
}