File tree Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Expand file tree Collapse file tree 2 files changed +15
-9
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 22extern crate anyhow;
33use anyhow:: Result ;
44use clap:: { Arg , Command } ;
5- use std:: fs;
65use std:: io;
7- use std:: io:: { Read , Write } ;
6+ use std:: io:: Read ;
87
98use mates:: cli;
109use mates:: utils;
@@ -90,6 +89,8 @@ fn main() -> Result<()> {
9089 & config. vdir_path ,
9190 ) ;
9291 contact. write_create ( ) ?;
92+
93+ cli:: index_contact ( & config. index_path , & contact) ?
9394 }
9495 Some ( ( "add-email" , _) ) => {
9596 let stdin = io:: stdin ( ) ;
@@ -98,13 +99,7 @@ fn main() -> Result<()> {
9899 let contact = utils:: add_contact_from_email ( & config. vdir_path , & email[ ..] ) ?;
99100 println ! ( "{}" , contact. path. display( ) ) ;
100101
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 ( ) ) ?;
102+ cli:: index_contact ( & config. index_path , & contact) ?
108103 }
109104 Some ( ( "edit" , args) ) => {
110105 if let Some ( value) = args. value_of ( "file-or-query" ) {
You can’t perform that action at this time.
0 commit comments