From e68d44afd57ca10d71b60560254064959a6ab869 Mon Sep 17 00:00:00 2001 From: piv <> Date: Sat, 4 Mar 2023 09:14:06 +1030 Subject: [PATCH] Upgrade to clap v4, add numeric accounts argument to allocate overheads cli --- Cargo.lock | 181 +++++++++++++++++++++++++++++++++++++++------------- Cargo.toml | 2 +- src/main.rs | 40 +++++++----- 3 files changed, 160 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 613b5f7..134ead0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,17 +26,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -103,26 +92,24 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.23" +version = "4.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" dependencies = [ - "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", + "is-terminal", "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" dependencies = [ "heck", "proc-macro-error", @@ -133,9 +120,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" dependencies = [ "os_str_bytes", ] @@ -286,10 +273,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] -name = "hashbrown" -version = "0.12.3" +name = "errno" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] [[package]] name = "heck" @@ -297,15 +299,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.2.6" @@ -315,6 +308,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "iana-time-zone" version = "0.1.53" @@ -340,13 +339,25 @@ dependencies = [ ] [[package]] -name = "indexmap" -version = "1.9.2" +name = "io-lifetimes" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" dependencies = [ - "autocfg", - "hashbrown", + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys", ] [[package]] @@ -381,9 +392,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "link-cplusplus" @@ -394,6 +405,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "log" version = "0.4.17" @@ -597,6 +614,20 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +[[package]] +name = "rustix" +version = "0.36.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.10" @@ -683,12 +714,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "time" version = "0.1.45" @@ -824,3 +849,69 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" diff --git a/Cargo.toml b/Cargo.toml index 5904b58..ed955bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ csv = "1.1" serde = { version = "1", features = ["derive"] } # num = "0.4" -clap = { version = "3.1.18", features = ["derive"] } +clap = { version = "4.1.8", features = ["derive"] } anyhow = "1.0" itertools = "0.10.3" diff --git a/src/main.rs b/src/main.rs index 1f41afb..5bdcd7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,10 +5,10 @@ use coster_rs::CsvCost; use serde::Deserialize; #[derive(Parser)] -#[clap(name = "coster-rs")] -#[clap(author = "Pivato M. ")] -#[clap(version = "0.0.1")] -#[clap(about = "Simple, fast, efficient costing tool", long_about = None)] +#[command(name = "coster-rs")] +#[command(author = "Pivato M. ")] +#[command(version = "0.0.1")] +#[command(about = "Simple, fast, efficient costing tool", long_about = None)] struct Cli { #[clap(subcommand)] command: Commands, @@ -18,44 +18,47 @@ struct Cli { enum Commands { /// Moves money between accounts and departments, using the given rules and lines move_money { - #[clap(short = 'r', long, parse(from_os_str), value_name = "FILE")] + #[arg(short = 'r', long, value_name = "FILE")] rules: PathBuf, - #[clap(short = 'l', long, parse(from_os_str), value_name = "FILE")] + #[arg(short = 'l', long, value_name = "FILE")] lines: PathBuf, - #[clap(short, long, parse(from_os_str), value_name = "FILE")] + #[arg(short, long, value_name = "FILE")] output: Option, - #[clap(short, long, default_value_t = false)] + #[arg(short, long)] use_numeric_accounts: bool, }, /// Combines rules to the minimum set required smush_rules { - #[clap(short = 'r', long, parse(from_os_str), value_name = "FILE")] + #[arg(short = 'r', long, value_name = "FILE")] rules: PathBuf, - #[clap(short, long, parse(from_os_str), value_name = "FILE")] + #[arg(short, long, value_name = "FILE")] output: Option, }, /// Allocates servicing department amounts to operating departments allocate_overheads { - #[clap(short, long, parse(from_os_str), value_name = "FILE")] + #[arg(short, long, value_name = "FILE")] lines: PathBuf, - #[clap(short, long, parse(from_os_str), value_name = "FILE")] + #[arg(short, long, value_name = "FILE")] accounts: PathBuf, - #[clap(short, long, parse(from_os_str), value_name = "FILE")] + #[arg(short = 's', long, value_name = "FILE")] allocation_statistics: PathBuf, - #[clap(short, long, parse(from_os_str), value_name = "FILE")] + #[arg(short, long, value_name = "FILE")] areas: PathBuf, - #[clap(short, long, parse(from_os_str), value_name = "FILE")] + #[arg(short, long, value_name = "FILE")] cost_centres: PathBuf, - #[clap(short, long, parse(from_os_str), value_name = "FILE")] + #[arg(short, long)] + use_numeric_accounts: bool, + + #[arg(short, long, value_name = "FILE")] output: Option, }, } @@ -77,6 +80,7 @@ fn main() -> anyhow::Result<()> { allocation_statistics, areas, cost_centres, + use_numeric_accounts, output, } => allocate_overheads( lines, @@ -84,6 +88,7 @@ fn main() -> anyhow::Result<()> { allocation_statistics, areas, cost_centres, + use_numeric_accounts, output, ), } @@ -113,6 +118,7 @@ fn allocate_overheads( allocation_statistics: PathBuf, areas: PathBuf, cost_centres: PathBuf, + use_numeric_accounts: bool, output: Option, ) -> anyhow::Result<()> { coster_rs::reciprocal_allocation( @@ -122,7 +128,7 @@ fn allocate_overheads( csv::Reader::from_path(areas)?, csv::Reader::from_path(cost_centres)?, &mut csv::Writer::from_path(output.unwrap_or(PathBuf::from("alloc_output.csv")))?, - true, + use_numeric_accounts, false, true, "E".to_owned(),