diff options
| author | Ellie Huxtable <e@elm.sh> | 2021-02-14 15:15:26 +0000 |
|---|---|---|
| committer | Ellie Huxtable <e@elm.sh> | 2021-02-14 15:35:08 +0000 |
| commit | 660edfefed7e658ed73ef64cd20582e390bb0cc5 (patch) | |
| tree | 39dde592e4ce6361eb69ff3cc402176caaf4dbe3 /src/command | |
| parent | Make clippy annoying asf + add server (diff) | |
| download | atuin-660edfefed7e658ed73ef64cd20582e390bb0cc5.zip | |
Make pedantic clippy happy
Diffstat (limited to '')
| -rw-r--r-- | src/command/history.rs | 14 | ||||
| -rw-r--r-- | src/command/import.rs | 139 | ||||
| -rw-r--r-- | src/command/server.rs | 9 |
3 files changed, 79 insertions, 83 deletions
diff --git a/src/command/history.rs b/src/command/history.rs index f8a5b27e..73be66fa 100644 --- a/src/command/history.rs +++ b/src/command/history.rs @@ -3,11 +3,11 @@ use std::env; use eyre::Result; use structopt::StructOpt; -use crate::local::database::{Database, SqliteDatabase}; +use crate::local::database::{Database, Sqlite}; use crate::local::history::History; #[derive(StructOpt)] -pub enum HistoryCmd { +pub enum Cmd { #[structopt( about="begins a new command in the history", aliases=&["s", "st", "sta", "star"], @@ -34,10 +34,10 @@ pub enum HistoryCmd { }, } -impl HistoryCmd { - pub fn run(&self, db: &mut SqliteDatabase) -> Result<()> { +impl Cmd { + pub fn run(&self, db: &mut Sqlite) -> Result<()> { match self { - HistoryCmd::Start { command: words } => { + Self::Start { command: words } => { let command = words.join(" "); let cwd = env::current_dir()?.display().to_string(); @@ -58,7 +58,7 @@ impl HistoryCmd { Ok(()) } - HistoryCmd::End { id, exit } => { + Self::End { id, exit } => { let mut h = db.load(id)?; h.exit = *exit; h.duration = chrono::Utc::now().timestamp_nanos() - h.timestamp; @@ -68,7 +68,7 @@ impl HistoryCmd { Ok(()) } - HistoryCmd::List { distinct } => db.list(*distinct), + Self::List { distinct } => db.list(*distinct), } } } diff --git a/src/command/import.rs b/src/command/import.rs index a593ef61..77db1c84 100644 --- a/src/command/import.rs +++ b/src/command/import.rs @@ -5,13 +5,13 @@ use eyre::{eyre, Result}; use home::home_dir; use structopt::StructOpt; -use crate::local::database::{Database, SqliteDatabase}; +use crate::local::database::{Database, Sqlite}; use crate::local::history::History; -use crate::local::import::ImportZsh; +use crate::local::import::Zsh; use indicatif::ProgressBar; #[derive(StructOpt)] -pub enum ImportCmd { +pub enum Cmd { #[structopt( about="import history for the current shell", aliases=&["a", "au", "aut"], @@ -25,94 +25,89 @@ pub enum ImportCmd { Zsh, } -impl ImportCmd { - fn import_zsh(&self, db: &mut SqliteDatabase) -> 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 :) - - let histpath = env::var("HISTFILE"); +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!("====================="); + println!("Importing history..."); - let histpath = match histpath { - Ok(p) => PathBuf::from(p), - Err(_) => { - let mut home = home_dir().unwrap(); - home.push(".zhistory"); + match self { + Self::Auto => { + let shell = env::var("SHELL").unwrap_or_else(|_| String::from("NO_SHELL")); - home + if shell.as_str() == "/bin/zsh" { + println!("Detected ZSH"); + import_zsh(db) + } else { + println!("cannot import {} history", shell); + Ok(()) + } } - }; - if !histpath.exists() { - return Err(eyre!( - "Could not find history file at {}, try setting $HISTFILE", - histpath.to_str().unwrap() - )); + Self::Zsh => import_zsh(db), } + } +} - let zsh = ImportZsh::new(histpath.to_str().unwrap())?; +fn import_zsh(db: &mut Sqlite) -> 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 :) - let progress = ProgressBar::new(zsh.loc); + let histpath = env::var("HISTFILE"); - let buf_size = 100; - let mut buf = Vec::<History>::with_capacity(buf_size); + let histpath = if let Ok(p) = histpath { + PathBuf::from(p) + } else { + let mut home = home_dir().unwrap(); + home.push(".zhistory"); - for i in zsh { - match i { - Ok(h) => { - buf.push(h); - } - Err(e) => { - error!("{}", e); - continue; - } - } + home + }; + + if !histpath.exists() { + return Err(eyre!( + "Could not find history file at {}, try setting $HISTFILE", + histpath.to_str().unwrap() + )); + } + + let zsh = Zsh::new(histpath.to_str().unwrap())?; + + let progress = ProgressBar::new(zsh.loc); - if buf.len() == buf_size { - db.save_bulk(&buf)?; - progress.inc(buf.len() as u64); + let buf_size = 100; + let mut buf = Vec::<History>::with_capacity(buf_size); - buf = Vec::<History>::with_capacity(buf_size); + for i in zsh { + match i { + Ok(h) => { + buf.push(h); + } + Err(e) => { + error!("{}", e); + continue; } } - if buf.len() > 0 { + if buf.len() == buf_size { db.save_bulk(&buf)?; progress.inc(buf.len() as u64); - } - progress.finish_with_message("Imported history!"); - - Ok(()) + buf = Vec::<History>::with_capacity(buf_size); + } } - pub fn run(&self, db: &mut SqliteDatabase) -> Result<()> { - println!(" A'Tuin "); - println!("====================="); - println!(" 🌍 "); - println!(" 🐘🐘🐘🐘 "); - println!(" 🐢 "); - println!("====================="); - println!("Importing history..."); - - match self { - ImportCmd::Auto => { - let shell = env::var("SHELL").unwrap_or(String::from("NO_SHELL")); - - match shell.as_str() { - "/bin/zsh" => { - println!("Detected ZSH"); - self.import_zsh(db) - } + if !buf.is_empty() { + db.save_bulk(&buf)?; + progress.inc(buf.len() as u64); + } - _ => { - println!("cannot import {} history", shell); - Ok(()) - } - } - } + progress.finish_with_message("Imported history!"); - ImportCmd::Zsh => self.import_zsh(db), - } - } + Ok(()) } diff --git a/src/command/server.rs b/src/command/server.rs index aee64c07..1ddc73e7 100644 --- a/src/command/server.rs +++ b/src/command/server.rs @@ -1,14 +1,15 @@ use eyre::Result; use structopt::StructOpt; -use crate::server::server; +use crate::remote::server; #[derive(StructOpt)] -pub enum ServerCmd { - Start { command: Vec<String> }, +pub enum Cmd { + Start { host: Vec<String> }, } -impl ServerCmd { +#[allow(clippy::unused_self)] // I'll use it later +impl Cmd { pub fn run(&self) -> Result<()> { server::launch(); Ok(()) |
