From c7b9f14d47b844776375be9c36739a6a7068d434 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Sun, 17 Dec 2023 09:07:38 +1000 Subject: [PATCH] Use clap conflicts_with --- src/main.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 93a3dd0c..8bb8ebef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,14 +35,9 @@ use std::fs::read_to_string; use std::io; use std::process::exit; -use anyhow::ensure; -use anyhow::Context; -use anyhow::Result; -use camino::Utf8Path; -use camino::Utf8PathBuf; -use clap::ArgAction; -use clap::CommandFactory; -use clap::Parser; +use anyhow::{anyhow, ensure, Context, Result}; +use camino::{Utf8Path, Utf8PathBuf}; +use clap::{ArgAction, CommandFactory, Parser}; use clap_complete::{generate, Shell}; use tracing::debug; @@ -100,7 +95,7 @@ struct Args { diff: bool, /// rust crate directory to examine. - #[arg(long, short = 'd')] + #[arg(long, short = 'd', conflicts_with = "manifest_path")] dir: Option, /// return this error values from functions returning Result: @@ -259,11 +254,9 @@ fn main() -> Result<()> { let start_dir: &Utf8Path = if let Some(manifest_path) = &args.manifest_path { ensure!(manifest_path.is_file(), "Manifest path is not a file"); - ensure!( - args.dir.is_none(), - "--dir and --manifest-path are mutually exclusive" - ); - manifest_path.parent().expect("Manifest path has no parent") + manifest_path + .parent() + .ok_or(anyhow!("Manifest path has no parent"))? } else if let Some(dir) = &args.dir { dir } else {