added autopsy option

main
nick 2024-10-10 12:58:39 -04:00
parent d4a28340d8
commit 454b0e4b78
2 changed files with 20 additions and 2 deletions

View File

@ -2,6 +2,11 @@ use clap::Parser;
#[derive(Parser)] #[derive(Parser)]
pub struct Args { pub struct Args {
/// open, print, and remove the log file
/// (if it exists)
#[arg(short, long)]
pub autopsy: bool,
/// root of the new filesystem /// root of the new filesystem
#[arg( #[arg(
default_value_t = String::from(".") default_value_t = String::from(".")

View File

@ -14,9 +14,9 @@ use terminal::Terminal;
use pane::prelude::*; use pane::prelude::*;
use std::fs::{remove_file, OpenOptions}; 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 clap::Parser;
use crossterm::event::{read, Event, KeyEvent}; use crossterm::event::{read, Event, KeyEvent};
use gag::Redirect; use gag::Redirect;
@ -27,6 +27,19 @@ const LOG_EXISTS_MSG: &str = "the log file exists, implying dirbuider didn't exi
fn main() -> AnyResult<()> { fn main() -> AnyResult<()> {
let args = Args::parse(); 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() let target = OpenOptions::new()
.write(true) .write(true)
.create_new(true) .create_new(true)