@@ -5,10 +5,15 @@ extern crate gdi32;
55#[ cfg( windows) ]
66extern crate user32;
77
8+ use std:: fs:: File ;
9+
10+ use clap:: { App , Arg , ArgMatches , SubCommand } ;
11+
812mod cert;
13+ mod install;
914mod utils;
1015
11- use clap :: { App , Arg , SubCommand } ;
16+ use install :: install ;
1217
1318fn main ( ) {
1419 let args = App :: new ( "mkcert" )
@@ -63,13 +68,10 @@ fn main() {
6368 . help ( "lengh of key, default 2048" )
6469 . takes_value ( true ) ,
6570 ) ,
66- ) ;
67-
68- let matches = args. get_matches ( ) ;
69-
70- let mut c = cert:: Cert :: new ( ) ;
71+ )
72+ . subcommand ( SubCommand :: with_name ( "install" ) . about ( "install ca to trusted store" ) ) ;
7173
72- if let Some ( matches ) = matches. subcommand_matches ( "init" ) {
74+ let get_init_args = | matches : & ArgMatches | {
7375 let length: u32 = matches
7476 . value_of ( "length" )
7577 . unwrap_or ( "2048" )
@@ -88,6 +90,16 @@ fn main() {
8890 false
8991 } ;
9092
93+ return ( cn, length, force) ;
94+ } ;
95+
96+ let matches = args. get_matches ( ) ;
97+
98+ let mut c = cert:: Cert :: new ( ) ;
99+
100+ if let Some ( matches) = matches. subcommand_matches ( "init" ) {
101+ let ( cn, length, force) = get_init_args ( & matches) ;
102+
91103 c. init ( & cn, length, force) ;
92104 }
93105
@@ -109,4 +121,18 @@ fn main() {
109121 eprintln ! ( "must provide a name!" ) ;
110122 }
111123 }
124+
125+ if let Some ( matches) = matches. subcommand_matches ( "install" ) {
126+ let ca = File :: open ( utils:: ca_path ( ) ) ;
127+ let key = File :: open ( utils:: key_path ( ) ) ;
128+
129+ if let ( Ok ( _ca) , Ok ( _key) ) = ( ca, key) {
130+ } else {
131+ let ( cn, length, force) = get_init_args ( & matches) ;
132+
133+ c. init ( & cn, length, force) ;
134+ }
135+
136+ install ( ) ;
137+ }
112138}
0 commit comments