From e821b287eb567627977087b49663717023d224ce Mon Sep 17 00:00:00 2001 From: red Date: Tue, 22 Oct 2024 14:05:10 +0200 Subject: [PATCH] Improvement: Replaced clap with argh --- CHANGELOG.md | 4 ++++ Cargo.toml | 4 ++-- src/main.rs | 23 +++++++++++------------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a418dd9..8e525bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ Of note: - The changelog 2015.5.2 has been rewritten from each commit content. - This file may be amended entirely in the future to adhere to the [GNU Changelog style](https://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html#Style-of-Change-Logs) +## [2018.6.3] +### Changed +- Replaced [Clap](https://github.com/clap-rs/clap) with [Argh](https://github.com/google/argh) for CLI input parsing, binaries are now 300k lighter. + ## [2018.6.2] ### Changed - Updated dependencies, changed all `ToString` implementations to `fmt::Display`, and other clippy improvements diff --git a/Cargo.toml b/Cargo.toml index a5e4160..773fd41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "advent-rs" -version = "2018.6.2" +version = "2018.6.3" edition = "2021" authors = ["Arnaud 'red' Rouyer"] readme = "README.md" @@ -32,7 +32,7 @@ panic = "abort" # Abort on panic # codegen-units = 1 # Reduce number of codegen units to increase optimizations. [dependencies] -clap = { version = "4.5.20", features = ["derive"] } +argh = "0.1.10" itertools = "0.13.0" md-5 = "0.10.6" diff --git a/src/main.rs b/src/main.rs index 721b59d..9892fb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,27 +1,26 @@ -use clap::Parser; +use argh::FromArgs; use std::fs; use std::io; use std::path::Path; use std::path::PathBuf; +#[derive(FromArgs)] /// Solver for advent of code exercises -#[derive(Parser, Debug)] -#[command(version, about, long_about = None)] struct Args { - /// The year of the exercise, from 2015 to today - #[arg(short, long, value_parser = clap::value_parser!(u16))] + /// year of the exercise, from 2015 to today + #[argh(option, short = 'y')] year: u16, - /// The day of the exercise, from 1 to 25 - #[arg(short, long, value_parser = clap::value_parser!(u8))] + /// day of the exercise, from 1 to 25 + #[argh(option, short = 'd')] day: u8, - /// The part of the exercise, 1 or 2 - #[arg(short, long, default_value_t = 1, value_parser = clap::value_parser!(u8))] + /// part of the exercise, 1 or 2 + #[argh(option, short = 'p', default = "1")] part: u8, - // File name - #[arg(help = "Input file path (will read from STDIN if empty)", value_parser = clap::value_parser!(PathBuf))] + /// file name + #[argh(positional, greedy)] input: Option, } @@ -48,7 +47,7 @@ pub fn fetch_input(file_path: Option>) -> Result input_data, Err(error) => {