Skip to content

Commit

Permalink
Friendlier shell support
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernthedev committed Dec 30, 2024
1 parent d00e21d commit 2fd3714
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/commands/ndk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ pub struct ResolveArgs {
/// Download package if necessary
#[clap(short, long, default_value = "false")]
download: bool,

#[clap(short, long, default_value = "false")]
ignore_missing: bool
}

fn fuzzy_match_ndk<'a>(
Expand Down Expand Up @@ -231,8 +234,18 @@ fn do_use(u: PinArgs) -> Result<(), color_eyre::eyre::Error> {
}

fn do_resolve(r: ResolveArgs) -> Result<(), color_eyre::eyre::Error> {
let package = PackageConfig::read(".")?;
let ndk_requirement = package.workspace.ndk.as_ref();
let package = PackageConfig::exists(".")
.then(|| PackageConfig::read("."))
.transpose()?;

if package.is_none() {
if r.ignore_missing {
return Ok(());
}
bail!("No package found in current directory")
}

let ndk_requirement = package.and_then(|p| p.workspace.ndk);
let Some(ndk_requirement) = ndk_requirement else {
bail!("No NDK requirement set in project")
};
Expand All @@ -252,7 +265,7 @@ fn do_resolve(r: ResolveArgs) -> Result<(), color_eyre::eyre::Error> {
// download
None if r.download => {
let manifest = get_android_manifest()?;
let (_version, ndk) = range_match_ndk(&manifest, ndk_requirement)?;
let (_version, ndk) = range_match_ndk(&manifest, &ndk_requirement)?;

download_ndk_version(ndk)?
}
Expand All @@ -266,7 +279,7 @@ fn do_resolve(r: ResolveArgs) -> Result<(), color_eyre::eyre::Error> {
let manifest = get_android_manifest().ok();
let mut suggested_version = manifest
.as_ref()
.and_then(|manifest| range_match_ndk(manifest, ndk_requirement).ok());
.and_then(|manifest| range_match_ndk(manifest, &ndk_requirement).ok());

if let Some((suggested_version, _)) = &mut suggested_version {
report = report.suggestion(format!("qpm ndk download {suggested_version}"));
Expand Down

0 comments on commit 2fd3714

Please sign in to comment.