Skip to main content

chronicle/cli/
import.rs

1use std::fs::File;
2use std::io::BufReader;
3
4use crate::error::Result;
5use crate::git::CliOps;
6use crate::import::import_annotations;
7
8/// Run `git chronicle import`.
9pub fn run(file: String, force: bool, dry_run: bool) -> Result<()> {
10    let repo_dir = std::env::current_dir().map_err(|e| crate::error::ChronicleError::Io {
11        source: e,
12        location: snafu::Location::default(),
13    })?;
14    let git_ops = CliOps::new(repo_dir);
15
16    let f = File::open(&file).map_err(|e| crate::error::ChronicleError::Io {
17        source: e,
18        location: snafu::Location::default(),
19    })?;
20    let reader = BufReader::new(f);
21
22    let summary = import_annotations(&git_ops, reader, force, dry_run)?;
23
24    if dry_run {
25        eprintln!("dry run: would import {} annotations", summary.imported);
26    } else {
27        eprintln!("imported {} annotations", summary.imported);
28    }
29
30    if summary.skipped_existing > 0 {
31        eprintln!("  skipped {} (already annotated)", summary.skipped_existing);
32    }
33    if summary.skipped_not_found > 0 {
34        eprintln!("  skipped {} (commit not found)", summary.skipped_not_found);
35    }
36    if summary.skipped_invalid > 0 {
37        eprintln!("  skipped {} (invalid entry)", summary.skipped_invalid);
38    }
39
40    Ok(())
41}