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 structopt::StructOpt;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::local::database::Sqlite;
|
||||||
|
|
||||||
mod history;
|
mod history;
|
||||||
mod import;
|
mod import;
|
||||||
|
@ -21,3 +25,18 @@ pub enum AtuinCmd {
|
||||||
#[structopt(about = "generates a UUID")]
|
#[structopt(about = "generates a UUID")]
|
||||||
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 chrono::Utc;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use eyre::{eyre, Result};
|
use eyre::Result;
|
||||||
|
|
||||||
use rusqlite::{params, Connection};
|
use rusqlite::{params, Connection};
|
||||||
use rusqlite::{Transaction, NO_PARAMS};
|
use rusqlite::{Transaction, NO_PARAMS};
|
||||||
|
@ -125,16 +125,11 @@ impl Database for Sqlite {
|
||||||
where id = ?1",
|
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)
|
history_from_sqlite_row(Some(id.to_string()), row)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let history = iter.next().unwrap();
|
Ok(history)
|
||||||
|
|
||||||
match history {
|
|
||||||
Ok(i) => Ok(i),
|
|
||||||
Err(e) => Err(eyre!("could not find item: {}", e)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&self, h: &History) -> Result<()> {
|
fn update(&self, h: &History) -> Result<()> {
|
||||||
|
|
|
@ -24,9 +24,9 @@ impl History {
|
||||||
session: Option<String>,
|
session: Option<String>,
|
||||||
hostname: Option<String>,
|
hostname: Option<String>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let session = session.unwrap_or_else(|| {
|
let session = session
|
||||||
env::var("ATUIN_SESSION").unwrap_or_else(|_| Uuid::new_v4().to_simple().to_string())
|
.or_else(|| env::var("ATUIN_SESSION").ok())
|
||||||
});
|
.unwrap_or_else(|| Uuid::new_v4().to_simple().to_string());
|
||||||
let hostname =
|
let hostname =
|
||||||
hostname.unwrap_or_else(|| hostname::get().unwrap().to_str().unwrap().to_string());
|
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::io::{BufRead, BufReader, Seek, SeekFrom};
|
||||||
use std::{fs::File, path::Path};
|
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)]
|
#[derive(Debug)]
|
||||||
pub struct Zsh {
|
pub struct Zsh {
|
||||||
|
@ -72,8 +72,6 @@ impl Iterator for Zsh {
|
||||||
|
|
||||||
match self.file.read_line(&mut line) {
|
match self.file.read_line(&mut line) {
|
||||||
Ok(0) => None,
|
Ok(0) => None,
|
||||||
Err(e) => Some(Err(eyre!("failed to parse line: {}", e))),
|
|
||||||
|
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let extended = line.starts_with(':');
|
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 directories::ProjectDirs;
|
||||||
use eyre::{eyre, Result};
|
use eyre::{eyre, Result};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
@ -46,26 +45,17 @@ impl Atuin {
|
||||||
let path = shellexpand::full(path)?;
|
let path = shellexpand::full(path)?;
|
||||||
PathBuf::from(path.as_ref())
|
PathBuf::from(path.as_ref())
|
||||||
} else {
|
} else {
|
||||||
let project_dirs =
|
ProjectDirs::from("com", "elliehuxtable", "atuin")
|
||||||
ProjectDirs::from("com", "elliehuxtable", "atuin").ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
eyre!("could not determine db file location\nspecify one using the --db flag")
|
eyre!("could not determine db file location\nspecify one using the --db flag")
|
||||||
})?;
|
})?
|
||||||
let root = project_dirs.data_dir();
|
.data_dir()
|
||||||
root.join("history.db")
|
.join("history.db")
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut db = Sqlite::new(db_path)?;
|
let mut db = Sqlite::new(db_path)?;
|
||||||
|
|
||||||
match self.atuin {
|
self.atuin.run(&mut db)
|
||||||
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(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue