Repository: mozilla/cargo-vet
Pull request #221 (2022-06-23 05:16:06)

Make read_line_initial_text omit prompt from the returned input.
Don't pass the prompt string to `console::read_line_initial_text`, as that causes it to include the prompt in the input: entering "2" and hitting ENTER returns the string "> 2". Just write the prompt to the console, and then call read_line_initial_text with a null string.

mystor: (thanks for the catch! @Gankra will merge this while I'm out)

Patch:
diff --git a/src/errors.rs b/src/errors.rs
index 933e530..3c46c35 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -43,7 +43,7 @@ pub struct NeedsAuditAsErrors {
 
 impl Display for NeedsAuditAsErrors {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        f.write_str("Some first-party packages match published crates.io versions")?;
+        f.write_str("Some non-crates.io-fetched packages match published crates.io versions")?;
         for e in &self.errors {
             f.write_fmt(format_args!("\n  {}", e))?
         }
diff --git a/src/main.rs b/src/main.rs
index 726e610..398ec70 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -684,7 +684,8 @@ fn do_cmd_certify(
                     .collect::<Vec<_>>()
             )?;
             writeln!(out, "(press ENTER to accept the current criteria)")?;
-            let input = out.read_line_initial_text("> ")?;
+            let input = out.read_line_with_prompt("> ")?;
+            dbg!(&input);
             let input = input.trim();
             if input.is_empty() {
                 if chosen_criteria.is_empty() {
diff --git a/src/out.rs b/src/out.rs
index 8ecda3c..1f57091 100644
--- a/src/out.rs
+++ b/src/out.rs
@@ -25,7 +25,7 @@ pub trait Out: io::Write {
 
     /// Ask the user a question, and read in a line with the user's response. If
     /// there's no user able to respond, `None` will be returned instead.
-    fn read_line_initial_text(&mut self, _initial: &str) -> io::Result<String> {
+    fn read_line_with_prompt(&mut self, _prompt: &str) -> io::Result<String> {
         Err(io::ErrorKind::Unsupported.into())
     }
 
@@ -53,8 +53,10 @@ impl Out for Term {
         (&*self).clear_screen()
     }
 
-    fn read_line_initial_text(&mut self, initial: &str) -> io::Result<String> {
-        (&*self).read_line_initial_text(initial)
+    fn read_line_with_prompt(&mut self, prompt: &str) -> io::Result<String> {
+        self.write_str(prompt)?;
+        self.flush()?;
+        (&*self).read_line()
     }
 
     fn style(&self) -> Style {


Test patch:
diff --git a/src/tests/mod.rs b/src/tests/mod.rs
index a00c279..8b820ab 100644
--- a/src/tests/mod.rs
+++ b/src/tests/mod.rs
@@ -1098,7 +1098,7 @@ impl<'a> Out for BasicTestOutput<'a> {
         Ok(())
     }
 
-    fn read_line_initial_text(&mut self, initial: &str) -> io::Result<String> {
+    fn read_line_with_prompt(&mut self, initial: &str) -> io::Result<String> {
         write!(self, "{}", initial)?;
         if let Some(on_read_line) = &mut self.on_read_line {
             let response = on_read_line(initial)?;
diff --git a/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__complex-audit-as-crates-io-max-wrong.snap b/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__complex-audit-as-crates-io-max-wrong.snap
index 7453e3d..d6d1040 100644
--- a/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__complex-audit-as-crates-io-max-wrong.snap
+++ b/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__complex-audit-as-crates-io-max-wrong.snap
@@ -6,7 +6,7 @@ expression: output
   × There are some issues with your policy.audit-as-crates-io entries
 
 Error: 
-  × Some first-party packages match published crates.io versions
+  × Some non-crates.io-fetched packages match published crates.io versions
   │   firstA:10.0.0
   │   firstAB:10.0.0
   │   firstB:10.0.0
diff --git a/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__complex-audit-as-crates-io.snap b/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__complex-audit-as-crates-io.snap
index 1dfad47..24aa646 100644
--- a/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__complex-audit-as-crates-io.snap
+++ b/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__complex-audit-as-crates-io.snap
@@ -6,7 +6,7 @@ expression: output
   × There are some issues with your policy.audit-as-crates-io entries
 
 Error: 
-  × Some first-party packages match published crates.io versions
+  × Some non-crates.io-fetched packages match published crates.io versions
   │   firstA:10.0.0
   │   firstAB:10.0.0
   │   firstB:10.0.0
diff --git a/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__simple-audit-as-crates-io.snap b/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__simple-audit-as-crates-io.snap
index 90263bd..3ca89fe 100644
--- a/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__simple-audit-as-crates-io.snap
+++ b/src/tests/snapshots/cargo_vet__tests__audit_as_crates_io__simple-audit-as-crates-io.snap
@@ -6,7 +6,7 @@ expression: output
   × There are some issues with your policy.audit-as-crates-io entries
 
 Error: 
-  × Some first-party packages match published crates.io versions
+  × Some non-crates.io-fetched packages match published crates.io versions
   │   root-package:10.0.0
   │   first-party:10.0.0
   help: Add a `policy.*.audit-as-crates-io` entry for them