Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made hidden features hidden on cargo add when not activated #10878

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,13 @@ fn print_msg(shell: &mut Shell, dep: &Dependency, section: &[String]) -> CargoRe
shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?;
}
for feat in deactivated {
shell.write_stderr(&prefix, &ColorSpec::new())?;
shell.write_stderr('-', &ColorSpec::new().set_bold(true).set_fg(Some(Red)))?;
shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?;
let is_hidden = feat.starts_with('_');

if !is_hidden {
johnmatthiggins marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this wasn't in the Issue but how about we also show these features when the user has increased the verbosity? We could use config.extra_verbose for now. Might be good to lower that to just verbose at a later point but that'll require some more rework because it isn't directly exposed

Copy link
Contributor Author

@johnmatthiggins johnmatthiggins Jul 21, 2022

Choose a reason for hiding this comment

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

I think this is a cool idea and I would love to implement it. However, given the existence of issue #10882 and my inexperience with this project, I'm not sure how to proceed with this PR. Should I wait for the requirements to be clearer before making any more changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend holding off until a determination has been made about #10794.

shell.write_stderr(&prefix, &ColorSpec::new())?;
shell.write_stderr('-', &ColorSpec::new().set_bold(true).set_fg(Some(Red)))?;
shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/testsuite/cargo_add/add_hidden_activated/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "main"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
hidden = { version = "0.1.0", path = "../hidden" }
3 changes: 3 additions & 0 deletions tests/testsuite/cargo_add/add_hidden_activated/in/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
20 changes: 20 additions & 0 deletions tests/testsuite/cargo_add/add_hidden_activated/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

use crate::cargo_add::init_registry;

#[cargo_test]
fn add_hidden_activated() {
init_registry();
let project = Project::from_template(curr_dir!().join("in"));
let cwd = &project.root();

snapbox::cmd::Command::cargo_ui()
.current_dir(cwd)
.args(&["add", "hidden-feature-test", "--features", "_secret"])
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
5 changes: 5 additions & 0 deletions tests/testsuite/cargo_add/add_hidden_activated/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Updating `dummy-registry` index
Adding hidden-feature-test v99999.0.0 to dependencies.
Features:
+ _secret
- not_secret
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "main"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
hidden = { version = "0.1.0", path = "../hidden" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
20 changes: 20 additions & 0 deletions tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

use crate::cargo_add::init_registry;

#[cargo_test]
fn add_hidden_unactivated() {
init_registry();
let project = Project::from_template(curr_dir!().join("in"));
let cwd = &project.root();

snapbox::cmd::Command::cargo_ui()
.current_dir(cwd)
.args(&["add", "hidden-feature-test"])
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
4 changes: 4 additions & 0 deletions tests/testsuite/cargo_add/add_hidden_unactivated/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Updating `dummy-registry` index
Adding hidden-feature-test v99999.0.0 to dependencies.
Features:
- not_secret
Empty file.
8 changes: 8 additions & 0 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod add_basic;
mod add_hidden_activated;
mod add_hidden_unactivated;
mod add_multiple;
mod add_normalized_name_external;
mod build;
Expand Down Expand Up @@ -185,4 +187,10 @@ fn add_registry_packages(alt: bool) {
.feature("eyes", &[])
.feature("ears", &[])
.publish();

cargo_test_support::registry::Package::new("hidden-feature-test", "99999.0.0+my-package")
.alternative(alt)
.feature("_secret", &[])
.feature("not_secret", &[])
.publish();
}