Skip to content

Ledger-cli (https://www.ledger-cli.org/) file processing Rust library, useful for calculating balances, creating reports etc.

License

Notifications You must be signed in to change notification settings

marek-g/rust-ledger-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ledger-utils

Crates.io Version Docs.rs Version License Unlicense

Ledger-cli file processing Rust library, useful for calculating balances, creating reports etc.

use anyhow::{bail, Result};
use ledger_utils::{balance::Balance, Ledger};

fn main() -> Result<()> {
    let ledger: Ledger = fs::read_to_string("finances.ledger")?.parse()?;

    if ledger.transactions.is_empty() {
        bail!("no transactions found");
    }

    let balance: Balance = (&ledger).into();

    let mut assets: Vec<_> = balance
        .account_balances
        .iter()
        .filter(|(name, _)| name.starts_with("Assets:"))
        .collect();
    assets.sort_by_key(|&(name, _)| name);
    for (name, balance) in assets {
        println!("{}: {}", name, balance);
    }

    Ok(())
}

About

Ledger-cli (https://www.ledger-cli.org/) file processing Rust library, useful for calculating balances, creating reports etc.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages