Skip to content

Commit

Permalink
manually implement version argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 2, 2020
1 parent f6c049c commit b397254
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ mod args {
#[derive(Debug, FromArgs)]
#[argh(subcommand, name = "diet")]
pub struct Diet {
#[argh(switch, short = 'v')]
/// if set, print the program version.
pub version: bool,

#[argh(switch, short = 'r')]
/// if set, existing include and exclude directives will be removed prior to running the command.
///
Expand Down Expand Up @@ -66,16 +70,19 @@ mod args {
use args::{Args, Diet, Subcommands};

fn main() -> anyhow::Result<()> {
let Args {
cmd:
Subcommands::Diet(Diet {
reset_manifest: reset,
dry_run,
package_size_limit,
#[cfg(feature = "dev-support")]
save_package_for_unit_test,
}),
} = argh::from_env();
let cmd = argh::from_env::<Args>().cmd;
let Subcommands::Diet(Diet {
version,
reset_manifest: reset,
dry_run,
package_size_limit,
#[cfg(feature = "dev-support")]
save_package_for_unit_test,
}) = cmd;
if version {
println!(env!("CARGO_PKG_VERSION"));
return Ok(());
}
cargo_diet::execute(
cargo_diet::Options {
reset,
Expand Down

0 comments on commit b397254

Please sign in to comment.