a few more tiny touch ups (#7)
* a few more tiny touch ups * all praise clippy
This commit is contained in:
parent
72c5ea7914
commit
bae59474ee
5 changed files with 34 additions and 31 deletions
|
@ -1,4 +1,8 @@
|
|||
use eyre::Result;
|
||||
use structopt::StructOpt;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::local::database::Sqlite;
|
||||
|
||||
mod history;
|
||||
mod import;
|
||||
|
@ -21,3 +25,18 @@ pub enum AtuinCmd {
|
|||
#[structopt(about = "generates a UUID")]
|
||||
Uuid,
|
||||
}
|
||||
|
||||
impl AtuinCmd {
|
||||
pub fn run(self, db: &mut Sqlite) -> Result<()> {
|
||||
match self {
|
||||
Self::History(history) => history.run(db),
|
||||
Self::Import(import) => import.run(db),
|
||||
Self::Server(server) => server.run(),
|
||||
|
||||
Self::Uuid => {
|
||||
println!("{}", Uuid::new_v4().to_simple().to_string());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use chrono::Utc;
|
||||
use std::path::Path;
|
||||
|
||||
use eyre::{eyre, Result};
|
||||
use eyre::Result;
|
||||
|
||||
use rusqlite::{params, Connection};
|
||||
use rusqlite::{Transaction, NO_PARAMS};
|
||||
|
@ -125,16 +125,11 @@ impl Database for Sqlite {
|
|||
where id = ?1",
|
||||
)?;
|
||||
|
||||
let mut iter = stmt.query_map(params![id], |row| {
|
||||
let history = stmt.query_row(params![id], |row| {
|
||||
history_from_sqlite_row(Some(id.to_string()), row)
|
||||
})?;
|
||||
|
||||
let history = iter.next().unwrap();
|
||||
|
||||
match history {
|
||||
Ok(i) => Ok(i),
|
||||
Err(e) => Err(eyre!("could not find item: {}", e)),
|
||||
}
|
||||
Ok(history)
|
||||
}
|
||||
|
||||
fn update(&self, h: &History) -> Result<()> {
|
||||
|
|
|
@ -24,9 +24,9 @@ impl History {
|
|||
session: Option<String>,
|
||||
hostname: Option<String>,
|
||||
) -> Self {
|
||||
let session = session.unwrap_or_else(|| {
|
||||
env::var("ATUIN_SESSION").unwrap_or_else(|_| Uuid::new_v4().to_simple().to_string())
|
||||
});
|
||||
let session = session
|
||||
.or_else(|| env::var("ATUIN_SESSION").ok())
|
||||
.unwrap_or_else(|| Uuid::new_v4().to_simple().to_string());
|
||||
let hostname =
|
||||
hostname.unwrap_or_else(|| hostname::get().unwrap().to_str().unwrap().to_string());
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
use std::io::{BufRead, BufReader, Seek, SeekFrom};
|
||||
use std::{fs::File, path::Path};
|
||||
|
||||
use eyre::{eyre, Result};
|
||||
use eyre::{Result, WrapErr};
|
||||
|
||||
use crate::local::history::History;
|
||||
use super::history::History;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Zsh {
|
||||
|
@ -72,8 +72,6 @@ impl Iterator for Zsh {
|
|||
|
||||
match self.file.read_line(&mut line) {
|
||||
Ok(0) => None,
|
||||
Err(e) => Some(Err(eyre!("failed to parse line: {}", e))),
|
||||
|
||||
Ok(_) => {
|
||||
let extended = line.starts_with(':');
|
||||
|
||||
|
@ -91,6 +89,7 @@ impl Iterator for Zsh {
|
|||
)))
|
||||
}
|
||||
}
|
||||
Err(e) => Some(Err(e).wrap_err("failed to parse line")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -8,7 +8,6 @@ use std::path::PathBuf;
|
|||
use directories::ProjectDirs;
|
||||
use eyre::{eyre, Result};
|
||||
use structopt::StructOpt;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
@ -46,26 +45,17 @@ impl Atuin {
|
|||
let path = shellexpand::full(path)?;
|
||||
PathBuf::from(path.as_ref())
|
||||
} else {
|
||||
let project_dirs =
|
||||
ProjectDirs::from("com", "elliehuxtable", "atuin").ok_or_else(|| {
|
||||
ProjectDirs::from("com", "elliehuxtable", "atuin")
|
||||
.ok_or_else(|| {
|
||||
eyre!("could not determine db file location\nspecify one using the --db flag")
|
||||
})?;
|
||||
let root = project_dirs.data_dir();
|
||||
root.join("history.db")
|
||||
})?
|
||||
.data_dir()
|
||||
.join("history.db")
|
||||
};
|
||||
|
||||
let mut db = Sqlite::new(db_path)?;
|
||||
|
||||
match self.atuin {
|
||||
AtuinCmd::History(history) => history.run(&mut db),
|
||||
AtuinCmd::Import(import) => import.run(&mut db),
|
||||
AtuinCmd::Server(server) => server.run(),
|
||||
|
||||
AtuinCmd::Uuid => {
|
||||
println!("{}", Uuid::new_v4().to_simple().to_string());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
self.atuin.run(&mut db)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue