aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock16
-rw-r--r--src/main.rs45
2 files changed, 50 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ee5552b..f90dbf2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,11 +1,3 @@
-[root]
-name = "passextract"
-version = "0.3.0"
-dependencies = [
- "clipboard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustty 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
[[package]]
name = "block"
version = "0.1.6"
@@ -92,6 +84,14 @@ dependencies = [
]
[[package]]
+name = "passextract"
+version = "0.3.0"
+dependencies = [
+ "clipboard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustty 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "pkg-config"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/main.rs b/src/main.rs
index 2a196d3..28b0259 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -78,11 +78,46 @@ fn parse_options(filename: &str) -> Vec<String> {
options
}
+/// Checks whether the given line starts with "p: "
+///
+/// # Examples
+///
+/// ```
+/// assert_eq!(is_password_line("p: secret"), true);
+/// ```
+fn is_password_line(line: &str) -> bool {
+ line.starts_with("p: ")
+}
+
+/// Replaces the password on a password line with "*"s.
+///
+/// # Examples
+///
+/// ```
+/// assert_eq!(hide_password_line("p: secret"), "p: ******);
+/// ```
+fn hide_password_line(line: &str) -> String {
+ const KEY_LENGTH: usize = 3;
+ let password_length = line.len() - KEY_LENGTH;
+
+ format!("p: {}", "*".repeat(password_length))
+}
+
fn main() {
let args: Vec<String> = env::args().collect();
- let input = if args.len() > 1 {
- &args[1]
+ let options = ["-i"];
+
+ let hide_password = match args.get(1) {
+ Some(arg) if arg == "-i" => true,
+ Some(_) => false,
+ None => false,
+ };
+
+ let last_arg = &args[args.len() - 1];
+ let input = if args.len() > 1 &&
+ !options.contains(&last_arg.as_ref()) {
+ last_arg
} else {
"-"
};
@@ -110,7 +145,11 @@ fn main() {
term.printline_with_cell(selection.x, selection.y, "->", knockout_cell);
for (i, s) in options.iter().enumerate() {
- term.printline(5, i + 2, s)
+ if hide_password && is_password_line(s) {
+ term.printline(5, i + 2, &hide_password_line(s))
+ } else {
+ term.printline(5, i + 2, s)
+ }
}
let evt = term.get_event(Duration::from_millis(100)).unwrap();