Skip to content

Commit

Permalink
feat(nargo): Stubbed out debug repl with placeholder command
Browse files Browse the repository at this point in the history
  • Loading branch information
nthiad committed Oct 2, 2023
1 parent 72c3661 commit c6b52f5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions tooling/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
62 changes: 62 additions & 0 deletions tooling/nargo_cli/src/cli/debug_cmd.rs
Original file line number Diff line number Diff line change
@@ -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<CrateName>,

/// 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<T>(args: ReplArgMatches, _context: &mut T) -> ReplResult<Option<String>> {
Ok(Some(format!(
"placeholder. x={}",
args.get_one::<String>("x").unwrap()
)))
}
3 changes: 3 additions & 0 deletions tooling/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit c6b52f5

Please sign in to comment.