:: lib::std::os::arguments;
values, captureError := arguments::capture();
if captureError != none {
fmt::eprintln("ledger: cannot capture command-line arguments");
command := values[1].view();
if command == "create" and values.len() == 3 {
result = commands::create(values[2].view());
} else if command == "append" and values.len() == 4 {
result = commands::append(values[2].view(), values[3].view());
} else if command == "verify" and values.len() == 3 {
result = commands::verify(values[2].view());
} else if command == "list" and values.len() == 3 {
result = commands::list(values[2].view());
} else if command == "help" or command == "--help" or command == "-h" {
result = model::LedgerError.Usage;
if result == model::LedgerError.Usage {
if result == model::LedgerError.InvalidFormat or
result == model::LedgerError.PayloadTooLarge {
fmt::eprintln("ledger: invalid ledger format");
if result == model::LedgerError.IntegrityFailure {
fmt::eprintln("ledger: integrity verification failed");
fmt::eprintln("ledger: operation failed");
fmt::println("ledger - deterministic append-only SHA-256 chain");
fmt::println(" ledger create <file>");
fmt::println(" ledger append <file> <payload>");
fmt::println(" ledger verify <file>");
fmt::println(" ledger list <file>");