mirror of
https://github.com/dtolnay/cargo-expand.git
synced 2025-04-03 12:57:38 +03:00
commit
8d8139502b
1 changed files with 18 additions and 19 deletions
37
src/main.rs
37
src/main.rs
|
@ -282,49 +282,49 @@ fn apply_args(cmd: &mut Command, args: &Expand, color: &Coloring, outfile: &Path
|
|||
line.arg("--no-default-features");
|
||||
}
|
||||
|
||||
let mut no_build_target = true;
|
||||
let mut has_explicit_build_target = false;
|
||||
if args.lib {
|
||||
line.arg("--lib");
|
||||
no_build_target = false;
|
||||
has_explicit_build_target = true;
|
||||
}
|
||||
|
||||
if let Some(bin) = &args.bin {
|
||||
line.arg("--bin");
|
||||
line.args(bin);
|
||||
no_build_target = false;
|
||||
has_explicit_build_target = true;
|
||||
}
|
||||
|
||||
if let Some(example) = &args.example {
|
||||
line.arg("--example");
|
||||
line.args(example);
|
||||
no_build_target = false;
|
||||
has_explicit_build_target = true;
|
||||
}
|
||||
|
||||
if let Some(test) = &args.test {
|
||||
line.arg("--test");
|
||||
line.args(test);
|
||||
no_build_target = false;
|
||||
has_explicit_build_target = true;
|
||||
}
|
||||
|
||||
if let Some(bench) = &args.bench {
|
||||
line.arg("--bench");
|
||||
line.args(bench);
|
||||
no_build_target = false;
|
||||
has_explicit_build_target = true;
|
||||
}
|
||||
|
||||
if no_build_target {
|
||||
match cargo_metadata(&args.manifest_path) {
|
||||
if !has_explicit_build_target {
|
||||
match cargo_metadata(args.manifest_path.as_deref()) {
|
||||
Ok(cargo_metadata) => {
|
||||
if let Some(root_package) = cargo_metadata.root_package() {
|
||||
if let Some(ref default_run) = root_package.default_run {
|
||||
if let Some(default_run) = &root_package.default_run {
|
||||
line.arg("--bin");
|
||||
line.args(Some(default_run));
|
||||
line.arg(default_run);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(err) => {
|
||||
let _ = writeln!(io::stderr(), "WARNING: run cargo metadata fail: {}", err);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -505,13 +505,12 @@ fn get_color(args: &Expand, config: &Config) -> Coloring {
|
|||
Coloring::Auto // default
|
||||
}
|
||||
|
||||
fn cargo_metadata(manifest_path: &Option<PathBuf>) -> cargo_metadata::Result<cargo_metadata::Metadata> {
|
||||
fn cargo_metadata(
|
||||
manifest_path: Option<&Path>,
|
||||
) -> cargo_metadata::Result<cargo_metadata::Metadata> {
|
||||
let mut cmd = cargo_metadata::MetadataCommand::new();
|
||||
match manifest_path {
|
||||
Some(manifest_path) => {
|
||||
cmd.manifest_path(manifest_path);
|
||||
},
|
||||
None => {},
|
||||
if let Some(manifest_path) = manifest_path {
|
||||
cmd.manifest_path(manifest_path);
|
||||
}
|
||||
cmd.exec()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue