Skip to content

Instantly share code, notes, and snippets.

@suluke
suluke / argh_cargo.rs
Created May 3, 2022 21:05
Auto-add --version flag in argh based on cargo's PKG_VERSION
//! Extend `argh` to be better integrated with the `cargo` ecosystem
//!
//! For now, this only adds a --version/-V option which causes early-exit.
use argh::{FromArgs, TopLevelCommand};
struct ArgsOrVersion<T: FromArgs>(T);
impl<T> argh::TopLevelCommand for ArgsOrVersion<T> where T: FromArgs {}
impl<T> FromArgs for ArgsOrVersion<T>
where
T: FromArgs,