implement backend command
This commit is contained in:
parent
4011cac6e9
commit
8cc1eb1cef
|
@ -18,6 +18,7 @@ pub mod month;
|
|||
pub mod list;
|
||||
pub mod out;
|
||||
pub mod resume;
|
||||
pub mod backend;
|
||||
|
||||
pub trait Command<'a> {
|
||||
type Args: TryFrom<&'a ArgMatches<'a>>;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
use std::process::{Command, Stdio};
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::config::Config;
|
||||
use crate::error::Error::*;
|
||||
|
||||
pub struct BackendCommand;
|
||||
|
||||
impl BackendCommand {
|
||||
pub fn handle(config: &Config) -> Result<()> {
|
||||
let status = Command::new("sqlite3")
|
||||
.arg(&config.database_file)
|
||||
.stdin(Stdio::inherit())
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit())
|
||||
.output().map_err(|e| Sqlite3CommandFailed(e))?
|
||||
.status;
|
||||
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Sqlite3CommandFailedUnkown)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -158,6 +158,14 @@ Is there a permissions issue? Here's the underlaying error:
|
|||
path: PathBuf,
|
||||
error: String,
|
||||
},
|
||||
|
||||
#[error("Trying to run system command sqlite3 failed with error:
|
||||
|
||||
{0}")]
|
||||
Sqlite3CommandFailed(std::io::Error),
|
||||
|
||||
#[error("Trying to run system command sqlite3 failed")]
|
||||
Sqlite3CommandFailedUnkown,
|
||||
}
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
|
|
@ -13,12 +13,16 @@ use tiempo::commands::{
|
|||
Command, r#in::InCommand, display::DisplayCommand, sheet::SheetCommand,
|
||||
today::TodayCommand, yesterday::YesterdayCommand, week::WeekCommand,
|
||||
month::MonthCommand, list::ListCommand, out::OutCommand,
|
||||
resume::ResumeCommand,
|
||||
resume::ResumeCommand, backend::BackendCommand,
|
||||
};
|
||||
|
||||
fn error_trap(matches: ArgMatches) -> error::Result<()> {
|
||||
let config = Config::read()?;
|
||||
|
||||
if let Some(_matches) = matches.subcommand_matches("backend") {
|
||||
return BackendCommand::handle(&config);
|
||||
}
|
||||
|
||||
let mut conn = SqliteDatabase::from_path_or_create(&config.database_file)?;
|
||||
let mut out = io::stdout();
|
||||
let mut err = io::stderr();
|
||||
|
|
Loading…
Reference in New Issue