Skip to content

Commit

Permalink
index the contact after add a contact
Browse files Browse the repository at this point in the history
  • Loading branch information
shalzz committed Apr 22, 2022
1 parent 5ee1d18 commit cb7b880
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ fn get_envvar(key: &str) -> Option<String> {
}
}

pub fn index_contact(index_path: &path::Path, contact: &utils::Contact) -> Result<()> {
let mut index_fp = fs::OpenOptions::new()
.append(true)
.write(true)
.open(&index_path)?;

let index_entry = utils::index_item_from_contact(&contact)?;
index_fp.write_all(index_entry.as_bytes())?;
Ok(())
}

pub fn build_index(outfile: &path::Path, dir: &path::Path) -> Result<()> {
if !dir.is_dir() {
return Err(anyhow!("MATES_DIR must be a directory."));
Expand Down
10 changes: 3 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ fn main() -> Result<()> {
&config.vdir_path,
);
contact.write_create()?;

cli::index_contact(&config.index_path, &contact)?
}
Some(("add-email", _)) => {
let stdin = io::stdin();
Expand All @@ -98,13 +100,7 @@ fn main() -> Result<()> {
let contact = utils::add_contact_from_email(&config.vdir_path, &email[..])?;
println!("{}", contact.path.display());

let mut index_fp = fs::OpenOptions::new()
.append(true)
.write(true)
.open(&config.index_path)?;

let index_entry = utils::index_item_from_contact(&contact)?;
index_fp.write_all(index_entry.as_bytes())?;
cli::index_contact(&config.index_path, &contact)?
}
Some(("edit", args)) => {
if let Some(value) = args.value_of("file-or-query") {
Expand Down

0 comments on commit cb7b880

Please sign in to comment.