From 1dacf979f2a01dbb5b54e2574ded7911587de2a5 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 21 Nov 2022 11:40:55 +0800 Subject: [PATCH] Use anonymous arg (#313) --- bin/subalfred/src/command/check/features.rs | 11 +++++++---- bin/subalfred/src/command/shared.rs | 16 ++++++++++------ bin/subalfred/src/command/workspace/update.rs | 2 +- .../src/command/workspace/update_deps.rs | 2 +- doc/src/user/cli/check.md | 11 ++++++----- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/bin/subalfred/src/command/check/features.rs b/bin/subalfred/src/command/check/features.rs index 1a0a1962..17e766fd 100644 --- a/bin/subalfred/src/command/check/features.rs +++ b/bin/subalfred/src/command/check/features.rs @@ -1,5 +1,5 @@ // std -use std::process; +use std::{path::PathBuf, process}; // crates.io use clap::Args; // hack-ink @@ -9,13 +9,16 @@ use subalfred_core::check::features; /// Check if the crates' features are enabled correctly. #[derive(Debug, Args)] pub(crate) struct FeaturesCmd { - #[command(flatten)] - manifest_path: ManifestPath, + /// Root `Cargo.toml`'s path. + /// + /// If `Cargo.toml` wasn't given, Subalfred will search it under the given path. + #[arg(value_name = "PATH", default_value = "./Cargo.toml")] + manifest_path: PathBuf, } impl FeaturesCmd { pub(crate) fn run(&self) -> Result<()> { let Self { manifest_path } = self; - let manifest_path = manifest_path.manifest_path(); + let manifest_path = ManifestPath::build_path(manifest_path); let manifest_path = manifest_path.to_string_lossy(); println!("checking: {manifest_path}"); diff --git a/bin/subalfred/src/command/shared.rs b/bin/subalfred/src/command/shared.rs index 3d527778..ad90944a 100644 --- a/bin/subalfred/src/command/shared.rs +++ b/bin/subalfred/src/command/shared.rs @@ -19,17 +19,21 @@ pub(crate) struct ManifestPath { pub(crate) manifest_path: PathBuf, } impl ManifestPath { - pub(crate) fn manifest_path(&self) -> Cow { - if self.manifest_path.is_file() { - Cow::Borrowed(&self.manifest_path) + pub(crate) fn build_path(path: &PathBuf) -> Cow { + if path.is_file() { + Cow::Borrowed(path) } else { - let mut manifest_path = self.manifest_path.clone(); + let mut path = path.to_owned(); - manifest_path.push("Cargo.toml"); + path.push("Cargo.toml"); - Cow::Owned(manifest_path) + Cow::Owned(path) } } + + pub(crate) fn path(&self) -> Cow { + Self::build_path(&self.manifest_path) + } } #[derive(Debug, Args)] diff --git a/bin/subalfred/src/command/workspace/update.rs b/bin/subalfred/src/command/workspace/update.rs index c126439c..85d742c3 100644 --- a/bin/subalfred/src/command/workspace/update.rs +++ b/bin/subalfred/src/command/workspace/update.rs @@ -18,7 +18,7 @@ impl UpdateCmd { pub(crate) async fn run(&self) -> Result<()> { let Self { version, manifest_path } = self; - cargo::update_member_versions(version, &manifest_path.manifest_path().to_string_lossy()) + cargo::update_member_versions(version, &manifest_path.path().to_string_lossy()) .await?; Ok(()) diff --git a/bin/subalfred/src/command/workspace/update_deps.rs b/bin/subalfred/src/command/workspace/update_deps.rs index 33cfa87a..712cd146 100644 --- a/bin/subalfred/src/command/workspace/update_deps.rs +++ b/bin/subalfred/src/command/workspace/update_deps.rs @@ -39,7 +39,7 @@ impl UpdateDepsCmd { cargo::update_dependency_versions( version, - &manifest_path.manifest_path().to_string_lossy(), + &manifest_path.path().to_string_lossy(), &targets.iter().map(AsRef::as_ref).collect::>(), ) .await?; diff --git a/doc/src/user/cli/check.md b/doc/src/user/cli/check.md index e23bf2d5..75aef0f3 100644 --- a/doc/src/user/cli/check.md +++ b/doc/src/user/cli/check.md @@ -165,21 +165,22 @@ RuntimeVersion { ``` Check if the crates' features are enabled correctly -Usage: subalfred check features [OPTIONS] +Usage: subalfred check features [OPTIONS] [PATH] -Options: - --manifest-path +Arguments: + [PATH] Root `Cargo.toml`'s path. If `Cargo.toml` wasn't given, Subalfred will search it under the given path. [default: ./Cargo.toml] +Options: -l, --log Set a custom log filter. - This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` - simultaneously, this will append `RUST_LOG`'s value after the log. + This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s + value after the log. [default: info]