@@ -4,10 +4,32 @@ use structopt::{
44 StructOpt ,
55} ;
66
7+ use std:: error:: Error ;
8+
9+ use crate :: errors:: { DevrcError , DevrcResult } ;
10+
711pub fn get_crate_version ( ) -> & ' static str {
812 env ! ( "CARGO_PKG_VERSION" )
913}
1014
15+ /// Parse a single key-value pair
16+ fn parse_key_val < T > ( s : & str ) -> DevrcResult < ( T , T ) >
17+ where
18+ T : std:: str:: FromStr ,
19+ T :: Err : Error + ' static ,
20+ {
21+ let pos = s. find ( '=' ) . ok_or ( {
22+ //format!("invalid KEY=value: no `=` found in `{}`", s)}
23+ DevrcError :: InvalidArgument
24+ } ) ?;
25+ Ok ( (
26+ s[ ..pos] . parse ( ) . map_err ( |_| DevrcError :: InvalidArgument ) ?,
27+ s[ pos + 1 ..]
28+ . parse ( )
29+ . map_err ( |_| DevrcError :: InvalidArgument ) ?,
30+ ) )
31+ }
32+
1133#[ derive( StructOpt , Debug ) ]
1234#[ structopt( version = get_crate_version( ) ) ]
1335#[ structopt( name = "devrc" ) ]
@@ -77,11 +99,10 @@ pub struct CommandLine {
7799 /// Suppress all output
78100 #[ structopt( short, long) ]
79101 pub quiet : bool ,
80- // #[structopt(subcommand)]
81- // pub sub: Option<Subcommands>, // /// Trailing newline behavior for the password. If "auto",
82- // // /// a trailing newline will be printed iff stdout is detected to be a tty.
83- // // #[structopt(long="newline", default_value="auto", raw(possible_values="&NewlineBehavior::variants()"))]
84- // // newline: NewlineBehavior
102+
103+ /// Override <VARIABLE> with <VALUE>
104+ #[ structopt( long = "--set" , parse( try_from_str = parse_key_val) , name="VAR=VALUE" ) ]
105+ pub set : Vec < ( String , String ) > ,
85106}
86107
87108impl CommandLine {
0 commit comments