diff --git a/tooling/nargo_cli/Cargo.toml b/tooling/nargo_cli/Cargo.toml index 0ae6073f0a1..bd9f14b035c 100644 --- a/tooling/nargo_cli/Cargo.toml +++ b/tooling/nargo_cli/Cargo.toml @@ -36,6 +36,7 @@ serde.workspace = true serde_json.workspace = true prettytable-rs = "0.10" rayon = "1.7.0" +reedline-repl-rs = "1.0.7" thiserror.workspace = true tower.workspace = true async-lsp = { version = "0.0.5", default-features = false, features = [ diff --git a/tooling/nargo_cli/src/cli/debug_cmd.rs b/tooling/nargo_cli/src/cli/debug_cmd.rs new file mode 100644 index 00000000000..931704b2bfd --- /dev/null +++ b/tooling/nargo_cli/src/cli/debug_cmd.rs @@ -0,0 +1,62 @@ +use clap::Args; +use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; +use noirc_driver::CompileOptions; +use noirc_frontend::graph::CrateName; +use crate::backends::Backend; +use crate::errors::CliError; +use super::NargoConfig; + +use reedline_repl_rs::clap::{ + Arg as ReplArg, + ArgMatches as ReplArgMatches, + Command as ReplCommand, +}; +use reedline_repl_rs::{Repl, Result as ReplResult}; + +/// Launches an interactve shell for debugging + +#[derive(Debug, Clone, Args)] +pub(crate) struct DebugCommand { + /// The name of the package to detail + #[clap(long, conflicts_with = "workspace")] + package: Option, + + /// Detail all packages in the workspace + #[clap(long, conflicts_with = "package")] + workspace: bool, + + #[clap(flatten)] + compile_options: CompileOptions, +} + +pub(crate) fn run( + _backend: &Backend, + args: DebugCommand, + config: NargoConfig, +) -> Result<(), CliError> { + let toml_path = get_package_manifest(&config.program_dir)?; + let default_selection = + if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; + let selection = args.package.map_or(default_selection, PackageSelection::Selected); + let _workspace = resolve_workspace_from_toml(&toml_path, selection)?; + + let mut repl = Repl::new(()) + .with_name("debug") + .with_version(env!["CARGO_PKG_VERSION"]) + .with_command( + ReplCommand::new("placeholder") + .arg(ReplArg::new("x").required(true)) + .about("placeholer command. remove me!"), + placeholder, + ); + repl.run().unwrap(); + + Ok(()) +} + +fn placeholder(args: ReplArgMatches, _context: &mut T) -> ReplResult> { + Ok(Some(format!( + "placeholder. x={}", + args.get_one::("x").unwrap() + ))) +} diff --git a/tooling/nargo_cli/src/cli/mod.rs b/tooling/nargo_cli/src/cli/mod.rs index 56d36095518..0324c7e8848 100644 --- a/tooling/nargo_cli/src/cli/mod.rs +++ b/tooling/nargo_cli/src/cli/mod.rs @@ -13,6 +13,7 @@ mod backend_cmd; mod check_cmd; mod codegen_verifier_cmd; mod compile_cmd; +mod debug_cmd; mod execute_cmd; mod info_cmd; mod init_cmd; @@ -58,6 +59,7 @@ enum NargoCommand { New(new_cmd::NewCommand), Init(init_cmd::InitCommand), Execute(execute_cmd::ExecuteCommand), + Debug(debug_cmd::DebugCommand), Prove(prove_cmd::ProveCommand), Verify(verify_cmd::VerifyCommand), Test(test_cmd::TestCommand), @@ -92,6 +94,7 @@ pub(crate) fn start_cli() -> eyre::Result<()> { NargoCommand::Init(args) => init_cmd::run(&backend, args, config), NargoCommand::Check(args) => check_cmd::run(&backend, args, config), NargoCommand::Compile(args) => compile_cmd::run(&backend, args, config), + NargoCommand::Debug(args) => debug_cmd::run(&backend, args, config), NargoCommand::Execute(args) => execute_cmd::run(&backend, args, config), NargoCommand::Prove(args) => prove_cmd::run(&backend, args, config), NargoCommand::Verify(args) => verify_cmd::run(&backend, args, config),