File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 1+ use std:: io:: { self , BufRead } ;
2+
13use clap:: { Args , value_parser} ;
2- use color_eyre:: eyre:: { ErrReport , Result } ;
4+ use color_eyre:: eyre:: { self , ErrReport , Result } ;
35
46use zeroize:: Zeroize ;
57
@@ -60,6 +62,10 @@ pub struct AddArgs {
6062 required_if_eq( "otp_type" , "MOTP" )
6163 ) ]
6264 pub pin : Option < String > ,
65+
66+ /// Pass the secret through the standard input
67+ #[ arg( long = "secret-stdin" , default_value_t = false ) ]
68+ take_secret_from_stdin : bool ,
6369}
6470
6571impl SubcommandExecutor for AddArgs {
@@ -79,7 +85,15 @@ impl SubcommandExecutor for AddArgs {
7985}
8086
8187fn get_from_args ( matches : AddArgs ) -> color_eyre:: Result < OTPElement > {
82- let secret = rpassword:: prompt_password ( "Insert the secret: " ) . map_err ( ErrReport :: from) ?;
88+ let secret = if matches. take_secret_from_stdin {
89+ if let Some ( password) = io:: stdin ( ) . lock ( ) . lines ( ) . next ( ) {
90+ password. map_err ( ErrReport :: from)
91+ } else {
92+ Err ( eyre:: eyre!( "Error during reading from stdin" ) )
93+ }
94+ } else {
95+ rpassword:: prompt_password ( "Insert the secret: " ) . map_err ( ErrReport :: from)
96+ } ?;
8397 map_args_to_code ( secret, matches)
8498}
8599
You can’t perform that action at this time.
0 commit comments