1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::common::Registry;
use clap::Args;
use semver::Version;
use std::path::PathBuf;
#[derive(Args)]
#[command(disable_version_flag = true)]
/// Resolve Rust source code from a crate
pub struct SourceArgs {
/// Path to the Cargo workspace or crate to inspect
#[arg(short = 'p', long, default_value = ".")]
path: PathBuf,
/// Registry to query when the crate is not present in local metadata
#[arg(long, value_enum, default_value_t = Registry::CratesIo)]
registry: Registry,
/// Print query/package/version/source metadata before the resolved Rust source
#[arg(short = 'v', long)]
verbose: bool,
/// List `library_name` -> `package_name` mappings for a package query
#[arg(short = 'l', long)]
libs: bool,
/// Resolve a specific crate version after metadata/cache lookup misses
#[arg(long)]
version: Option<Version>,
/// Remove the source cache for the selected registry before resolving
#[arg(long)]
clean: bool,
/// Rust path to resolve(start always by `package_name`), for example `cf-modkit` it will resolve the lib.rs
/// You can resolve modules `tokio::sync` to resolve the source code from the sync module from tokio crate
/// You can also resolve by function name, for example `cf-modkit::gts::plugin::BaseModkitPluginV1`
/// Also resolve by function name, for instance `cf-modkit::gts::schemas::get_core_gts_schemas`
query: Option<String>,
}
impl SourceArgs {
pub fn run(self) -> anyhow::Result<()> {
cargo_gears_core::source::SourceParams::from(self).run()
}
}
impl From<SourceArgs> for cargo_gears_core::source::SourceParams {
fn from(args: SourceArgs) -> Self {
Self {
path: args.path,
registry: args.registry,
verbose: args.verbose,
libs: args.libs,
version: args.version,
clean: args.clean,
query: args.query,
}
}
}