added autopsy option
parent
d4a28340d8
commit
454b0e4b78
|
@ -2,6 +2,11 @@ use clap::Parser;
|
|||
|
||||
#[derive(Parser)]
|
||||
pub struct Args {
|
||||
/// open, print, and remove the log file
|
||||
/// (if it exists)
|
||||
#[arg(short, long)]
|
||||
pub autopsy: bool,
|
||||
|
||||
/// root of the new filesystem
|
||||
#[arg(
|
||||
default_value_t = String::from(".")
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -14,9 +14,9 @@ use terminal::Terminal;
|
|||
use pane::prelude::*;
|
||||
|
||||
use std::fs::{remove_file, OpenOptions};
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::io::{read_to_string, Error, ErrorKind};
|
||||
|
||||
use anyhow::{Result as AnyResult, Error as AnyError};
|
||||
use anyhow::{Context, Error as AnyError, Result as AnyResult};
|
||||
use clap::Parser;
|
||||
use crossterm::event::{read, Event, KeyEvent};
|
||||
use gag::Redirect;
|
||||
|
@ -27,6 +27,19 @@ const LOG_EXISTS_MSG: &str = "the log file exists, implying dirbuider didn't exi
|
|||
fn main() -> AnyResult<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
if args.autopsy {
|
||||
let f = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(LOG_FILE)
|
||||
.map_err(Into::<AnyError>::into)
|
||||
.context(LOG_FILE)?;
|
||||
let s = read_to_string(f)?;
|
||||
eprint!("{s}");
|
||||
remove_file(LOG_FILE)?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let target = OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
|
|
Loading…
Reference in New Issue