File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,17 @@ fn get_envvar(key: &str) -> Option<String> {
2626 }
2727}
2828
29+ pub fn index_contact ( index_path : & path:: Path , contact : & utils:: Contact ) -> Result < ( ) > {
30+ let mut index_fp = fs:: OpenOptions :: new ( )
31+ . append ( true )
32+ . write ( true )
33+ . open ( & index_path) ?;
34+
35+ let index_entry = utils:: index_item_from_contact ( & contact) ?;
36+ index_fp. write_all ( index_entry. as_bytes ( ) ) ?;
37+ Ok ( ( ) )
38+ }
39+
2940pub fn build_index ( outfile : & path:: Path , dir : & path:: Path ) -> Result < ( ) > {
3041 if !dir. is_dir ( ) {
3142 return Err ( anyhow ! ( "MATES_DIR must be a directory." ) ) ;
Original file line number Diff line number Diff line change @@ -90,6 +90,8 @@ fn main() -> Result<()> {
9090 & config. vdir_path ,
9191 ) ;
9292 contact. write_create ( ) ?;
93+
94+ cli:: index_contact ( & config. index_path , & contact) ?
9395 }
9496 Some ( ( "add-email" , _) ) => {
9597 let stdin = io:: stdin ( ) ;
@@ -98,13 +100,7 @@ fn main() -> Result<()> {
98100 let contact = utils:: add_contact_from_email ( & config. vdir_path , & email[ ..] ) ?;
99101 println ! ( "{}" , contact. path. display( ) ) ;
100102
101- let mut index_fp = fs:: OpenOptions :: new ( )
102- . append ( true )
103- . write ( true )
104- . open ( & config. index_path ) ?;
105-
106- let index_entry = utils:: index_item_from_contact ( & contact) ?;
107- index_fp. write_all ( index_entry. as_bytes ( ) ) ?;
103+ cli:: index_contact ( & config. index_path , & contact) ?
108104 }
109105 Some ( ( "edit" , args) ) => {
110106 if let Some ( value) = args. value_of ( "file-or-query" ) {
You can’t perform that action at this time.
0 commit comments