aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/import.rs
diff options
context:
space:
mode:
authorConrad Ludgate <conradludgate@gmail.com>2021-02-15 09:07:49 +0000
committerGitHub <noreply@github.com>2021-02-15 09:07:49 +0000
commit68c5ca9ecedb6001c61e933f2b7069c2e677213d (patch)
treeca04351dd4309e77b1091f9a7ce10a7b4ae10ade /src/command/import.rs
parentUpdate README.md (diff)
downloadatuin-68c5ca9ecedb6001c61e933f2b7069c2e677213d.zip
use database trait instead of sqlite impl (#10)
small improvements
Diffstat (limited to '')
-rw-r--r--src/command/import.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/command/import.rs b/src/command/import.rs
index 88108400..4c3714b5 100644
--- a/src/command/import.rs
+++ b/src/command/import.rs
@@ -5,7 +5,7 @@ use directories::UserDirs;
use eyre::{eyre, Result};
use structopt::StructOpt;
-use crate::local::database::{Database, Sqlite};
+use crate::local::database::Database;
use crate::local::history::History;
use crate::local::import::Zsh;
use indicatif::ProgressBar;
@@ -26,13 +26,13 @@ pub enum Cmd {
}
impl Cmd {
- pub fn run(&self, db: &mut Sqlite) -> Result<()> {
- println!(" A'Tuin ");
- println!("=====================");
- println!(" \u{1f30d} ");
- println!(" \u{1f418}\u{1f418}\u{1f418}\u{1f418} ");
- println!(" \u{1f422} ");
- println!("=====================");
+ pub fn run(&self, db: &mut impl Database) -> Result<()> {
+ println!(" A'Tuin ");
+ println!("======================");
+ println!(" \u{1f30d} ");
+ println!(" \u{1f418}\u{1f418}\u{1f418}\u{1f418} ");
+ println!(" \u{1f422} ");
+ println!("======================");
println!("Importing history...");
match self {
@@ -53,7 +53,7 @@ impl Cmd {
}
}
-fn import_zsh(db: &mut Sqlite) -> Result<()> {
+fn import_zsh(db: &mut impl Database) -> Result<()> {
// oh-my-zsh sets HISTFILE=~/.zhistory
// zsh has no default value for this var, but uses ~/.zhistory.
// we could maybe be smarter about this in the future :)
@@ -65,8 +65,8 @@ fn import_zsh(db: &mut Sqlite) -> Result<()> {
if !histpath.exists() {
return Err(eyre!(
- "Could not find history file at {}",
- histpath.to_str().unwrap()
+ "Could not find history file {:?}. try updating $HISTFILE",
+ histpath
));
}
@@ -89,7 +89,7 @@ fn import_zsh(db: &mut Sqlite) -> Result<()> {
}
};
- let zsh = Zsh::new(histpath.to_str().unwrap())?;
+ let zsh = Zsh::new(histpath)?;
let progress = ProgressBar::new(zsh.loc);
@@ -106,7 +106,7 @@ fn import_zsh(db: &mut Sqlite) -> Result<()> {
db.save_bulk(&buf)?;
progress.inc(buf.len() as u64);
- buf = Vec::<History>::with_capacity(buf_size);
+ buf.clear();
}
}