diff options
author | Teddy Wing | 2016-08-06 07:29:17 -0400 |
---|---|---|
committer | Teddy Wing | 2016-08-06 07:29:17 -0400 |
commit | 494742673e26628f9b98185321db737b936af954 (patch) | |
tree | c04cfbbe7c11fd778ce255702089ddc39edeed66 /src/main.rs | |
parent | 97feec40b57031156196af7c61ccbc2aba6ec8d7 (diff) | |
download | Passextract-494742673e26628f9b98185321db737b936af954.tar.bz2 |
Call `pass show` with the given argument and run Passextract on result
Temporarily comment out code that deals with STDIN to get this feature
working. It complicated things to leave it in right now.
Given an argument that isn't "-" (STDIN), we pass that argument to `pass
show`. Users correctly get a password prompt from `pass`, and the output
from the command gets sent to the Passextract TUI for display in the
menu and copying.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 4a18223..ebe1683 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,8 +6,9 @@ use clipboard::ClipboardContext; use rustty::{Terminal, Event, Cell, Color, Attr}; use rustty::ui::Painter; +use std::env; use std::io::{self, BufRead}; -use std::process; +use std::process::{self, Command}; use std::time::Duration; struct Point { @@ -38,11 +39,24 @@ fn move_selection(term: &mut Terminal, selection: &mut Point, style: Cell, amoun } fn main() { + let args: Vec<String> = env::args().collect(); + + let input = if args.len() > 1 { + &args[1] + } else { + "-" + }; + + let file = Command::new("pass") + .arg("show") + .arg(input) + .output() + .expect("Error executing `pass`") + .stdout; + + let output = String::from_utf8_lossy(&file); let mut options = Vec::new(); - let stdin = io::stdin(); - for line in stdin.lock().lines() { - let line = line.expect("Error reading from STDIN"); - + for line in output.lines() { if line.starts_with("e: ") || line.starts_with("u: ") || line.starts_with("p: ") { @@ -50,6 +64,18 @@ fn main() { } } + // let mut options = Vec::new(); + // let stdin = io::stdin(); + // for line in stdin.lock().lines() { + // let line = line.expect("Error reading from STDIN"); + // + // if line.starts_with("e: ") || + // line.starts_with("u: ") || + // line.starts_with("p: ") { + // options.push(line); + // } + // } + if options.is_empty() { process::exit(1); } |