Skip to content

Commit

Permalink
Use anonymous arg (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier authored Nov 21, 2022
1 parent e9cdcb3 commit 1dacf97
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
11 changes: 7 additions & 4 deletions bin/subalfred/src/command/check/features.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// std
use std::process;
use std::{path::PathBuf, process};
// crates.io
use clap::Args;
// hack-ink
Expand All @@ -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}");
Expand Down
16 changes: 10 additions & 6 deletions bin/subalfred/src/command/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ pub(crate) struct ManifestPath {
pub(crate) manifest_path: PathBuf,
}
impl ManifestPath {
pub(crate) fn manifest_path(&self) -> Cow<PathBuf> {
if self.manifest_path.is_file() {
Cow::Borrowed(&self.manifest_path)
pub(crate) fn build_path(path: &PathBuf) -> Cow<PathBuf> {
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<PathBuf> {
Self::build_path(&self.manifest_path)
}
}

#[derive(Debug, Args)]
Expand Down
2 changes: 1 addition & 1 deletion bin/subalfred/src/command/workspace/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion bin/subalfred/src/command/workspace/update_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>(),
)
.await?;
Expand Down
11 changes: 6 additions & 5 deletions doc/src/user/cli/check.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 <TARGET=LEVEL,*>
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]
Expand Down

0 comments on commit 1dacf97

Please sign in to comment.