From c736e3be8fec3dff5dde94810b36f3a41a4122ee Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 13 Jan 2024 13:39:30 -0500 Subject: [PATCH] Move syntax tree CLI flag to a command --- src/main.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index be91620..fb5456f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,10 +29,6 @@ struct Args { #[arg(short = 'p', long)] input_path: Option, - /// Show the syntax tree. - #[arg(short = 't', long = "tree")] - show_syntax_tree: bool, - #[command(subcommand)] cli_command: Option, @@ -42,7 +38,11 @@ struct Args { #[derive(Subcommand, Debug)] pub enum CliCommand { + /// Output a formatted version of the input. Format, + + /// Output a concrete syntax tree of the input. + Syntax, } fn main() { @@ -80,14 +80,22 @@ fn main() { let mut interpreter = Interpreter::new(context); - if args.show_syntax_tree { + if let Some(CliCommand::Syntax) = args.cli_command { interpreter.parse(&source).unwrap(); println!("{}", interpreter.syntax_tree().unwrap()); + + return; } let eval_result = interpreter.run(&source); + if let Some(CliCommand::Format) = args.cli_command { + println!("{}", interpreter.format()); + + return; + } + match eval_result { Ok(value) => { if !value.is_none() { @@ -96,10 +104,6 @@ fn main() { } Err(error) => eprintln!("{error}"), } - - if let Some(CliCommand::Format) = args.cli_command { - println!("{}", interpreter.format()); - } } #[derive(Helper, Completer, Validator)]