Skip to content

Commit

Permalink
Improvement: Replaced clap with argh
Browse files Browse the repository at this point in the history
  • Loading branch information
joshleaves committed Oct 22, 2024
1 parent 2ff8e13 commit e821b28
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down
23 changes: 11 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf>,
}

Expand All @@ -48,7 +47,7 @@ pub fn fetch_input(file_path: Option<impl AsRef<Path>>) -> Result<String, std::i
/// * `part` - The part of the exercise, 1 or 2.
/// * `input` - Input file path (will read from STDIN if empty).
fn main() {
let args = Args::parse();
let args: Args = argh::from_env();
let input: String = match fetch_input(args.input) {
Ok(input_data) => input_data,
Err(error) => {
Expand Down

0 comments on commit e821b28

Please sign in to comment.