Make debug commands passable as parameters

This commit is contained in:
Olivier 'reivilibre' 2021-09-06 21:37:57 +01:00
parent ed758a8eaf
commit 33f18c4aeb
2 changed files with 25 additions and 5 deletions

View File

@ -24,6 +24,7 @@ use log::info;
use env_logger::Env;
use std::sync::Arc;
use yama::commands::{fully_integrate_pointer_node, load_pile_descriptor, open_pile};
use yama::debug::{debug_command, DebugCommand};
use yama::operations::checking::VacuumMode;
use yama::operations::pushpull::{determine_bypass_level, open_pile_with_work_bypass, push_to};
use yama::operations::{checking, extracting};
@ -80,7 +81,7 @@ enum PileCommand {
},
/// Enter a debug prompt for manually operating on the yama pile.
Debug,
Debug { supplied_command: Vec<String> },
/// Pushes a pointer from this pile to another pile.
Push {
@ -169,9 +170,28 @@ fn main() -> anyhow::Result<()> {
commands::init(".".as_ref())?;
}
PileCommand::Debug => {
PileCommand::Debug { supplied_command } => {
let (pdesc, pile) = open_pile()?;
debug::debug_prompt(pdesc, pile)?;
if supplied_command.is_empty() {
debug::debug_prompt(pdesc, pile)?;
} else {
let mut prefixed_command = vec![String::from("yama-debug")];
prefixed_command.extend(supplied_command.iter().cloned());
match DebugCommand::try_parse_from(prefixed_command) {
Ok(command) => {
if let Err(e) = debug_command(&pdesc, &pile, command) {
eprintln!("Failed {:?}", e);
std::process::exit(2);
} else {
std::process::exit(0);
}
}
Err(err) => {
eprintln!("Invalid {:?}", err);
std::process::exit(3);
}
}
}
}
PileCommand::Push {

View File

@ -26,7 +26,7 @@ use rustyline::error::ReadlineError;
use rustyline::Editor;
#[derive(Clap)]
enum DebugCommand {
pub enum DebugCommand {
/// List the pointers that are stored in this yama pile.
#[clap(name = "lsp")]
ListPointers {
@ -90,7 +90,7 @@ pub fn debug_prompt<RP: RawPile>(pdesc: PileDescriptor, pile: Pile<RP>) -> anyho
Ok(())
}
fn debug_command<RP: RawPile>(
pub fn debug_command<RP: RawPile>(
_pdesc: &PileDescriptor,
pile: &Pile<RP>,
command: DebugCommand,