Skip to content

Commit

Permalink
Add --direct-dependencies-only option
Browse files Browse the repository at this point in the history
  • Loading branch information
BennD committed Dec 4, 2023
1 parent 297b09e commit 38a05fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) struct Config {
pub include: Vec<String>,
pub root: Vec<String>,
pub workspace_only: bool,
pub direct_dependencies_only: bool,
pub focus: Vec<String>,

pub features: Vec<String>,
Expand Down Expand Up @@ -108,6 +109,12 @@ pub(crate) fn parse_options() -> Config {
.action(ArgAction::SetTrue)
.help("Exclude all packages outside of the workspace"),
)
.arg(
Arg::new("direct_dependencies_only")
.long("direct-dependencies-only")
.action(ArgAction::SetTrue)
.help("Only list direct dependencies of workspace crates"),
)
.arg(
Arg::new("focus")
.long("focus")
Expand Down Expand Up @@ -198,6 +205,7 @@ pub(crate) fn parse_options() -> Config {
let include = matches.get_many("include").map_or_else(Vec::new, collect_owned);
let root = matches.get_many("root").map_or_else(Vec::new, collect_owned);
let workspace_only = matches.get_flag("workspace_only");
let direct_dependencies_only = matches.get_flag("direct_dependencies_only");
let focus = matches.get_many("focus").map_or_else(Vec::new, collect_owned);

let features = matches.get_many("features").map_or_else(Vec::new, collect_owned);
Expand All @@ -220,6 +228,7 @@ pub(crate) fn parse_options() -> Config {
include,
root,
workspace_only,
direct_dependencies_only,
focus,
features,
all_features,
Expand Down
7 changes: 6 additions & 1 deletion src/graph/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ pub(crate) fn get_dep_graph(metadata: Metadata, config: &Config) -> anyhow::Resu
}

let idx = graph.add_node(dep_pkg);
deps_add_queue.push_back(dep.pkg.clone());

// Don't add any more dependencies to the queue if we only want direct dependencies
if !config.direct_dependencies_only {
deps_add_queue.push_back(dep.pkg.clone());
}

v.insert(idx);
idx
}
Expand Down

7 comments on commit 38a05fe

@AlexandreCassagne
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you haha, I was JUST (1 minute ago) trying to do --depth=1 :D

@jplatte
Copy link
Owner

@jplatte jplatte commented on 38a05fe Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea, that would be more general and shorter to spell out on the command line. Do you mind opening an issue for it, or even send a PR to replace this feature?

@BennD
Copy link
Contributor Author

@BennD BennD commented on 38a05fe Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, i didn't think about that, as it didn't work for another crate i tried before, because they didn't take the workspace as root, but one single package instead. That way --depth 1 didn't work for this.

@AlexandreCassagne
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BennD Are you saying that the direct-dependencies-only is not equivalent to depth=1?

@AlexandreCassagne
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or that, in this package, it would be equivalent?

@AlexandreCassagne
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18

@BennD
Copy link
Contributor Author

@BennD BennD commented on 38a05fe Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BennD Are you saying that the direct-dependencies-only is not equivalent to depth=1?
Or that, in this package, it would be equivalent?

@AlexandreCassagne In this package, it would be equivalent.

Please sign in to comment.