Skip to content

Commit 2ae3d21

Browse files
committed
Consolidate command execution through runner abstraction
The changes migrate various command executions (nargo, garaga, foundry) to use a common runner abstraction, removing direct backend calls in favor of a more unified approach to command execution.
1 parent d8b1993 commit 2ae3d21

File tree

2 files changed

+77
-12
lines changed

2 files changed

+77
-12
lines changed

crates/bargo-core/src/commands/build.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use color_eyre::Result;
22

33
use crate::{
4-
backends,
54
commands::common::run_nargo_command,
65
config::Config,
76
util::{self, Flavour, Timer, format_operation_result, success},
@@ -15,13 +14,6 @@ pub fn should_rebuild(pkg: &str, cfg: &Config) -> Result<bool> {
1514
util::needs_rebuild(pkg)
1615
}
1716

18-
/// Run `nargo execute` with the provided arguments.
19-
///
20-
/// The slice is typically produced by [`build_nargo_args`].
21-
pub fn run_nargo_execute(args: &[&str]) -> Result<()> {
22-
backends::nargo::run(args)
23-
}
24-
2517
/// Execute the build workflow
2618
pub fn run(cfg: &Config) -> Result<()> {
2719
if cfg.dry_run {

crates/bargo-core/src/commands/common.rs

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn build_nargo_args(cfg: &Config, base_args: &[&str]) -> Result<Vec<String>>
3838
/// - Building arguments with global flags via `build_nargo_args`
3939
/// - Verbose logging (when enabled and not quiet)
4040
/// - Dry-run mode (prints command without executing)
41-
/// - Backend execution via `backends::nargo::run`
41+
/// - Command execution via the configured runner
4242
///
4343
/// # Arguments
4444
/// * `cfg` - The global configuration containing all flags
@@ -66,10 +66,83 @@ pub fn run_nargo_command(cfg: &Config, base_args: &[&str]) -> Result<()> {
6666
cfg.runner.run(&spec)
6767

6868
// TODO: Migrate remaining shell-outs to use runner abstraction:
69-
// - backends::nargo::run calls in other modules
70-
// - scarb command executions
71-
// - garaga command executions
69+
// - scarb command executions (currently empty module)
7270
// - starknet CLI integrations
71+
//
72+
// Completed migrations:
73+
// ✅ bb command executions
74+
// ✅ garaga command executions
75+
// ✅ foundry command executions
76+
// ✅ nargo command executions
77+
}
78+
79+
/// Run a garaga command with consolidated argument building, logging, and dry-run handling
80+
///
81+
/// This is the primary helper for executing garaga commands consistently across all
82+
/// command modules. It handles:
83+
/// - Verbose logging (when enabled and not quiet)
84+
/// - Dry-run mode (prints command without executing)
85+
/// - Command execution via the configured runner
86+
///
87+
/// # Arguments
88+
/// * `cfg` - The global configuration containing all flags and runner
89+
/// * `args` - Arguments to pass to garaga
90+
///
91+
/// # Returns
92+
/// * `Result<()>` - Success or error from command execution
93+
///
94+
/// # Example
95+
/// ```ignore
96+
/// // Execute "garaga gen --system ultra_starknet_zk_honk --vk ./target/starknet/vk"
97+
/// run_garaga_command(&config, &["gen", "--system", "ultra_starknet_zk_honk", "--vk", "./target/starknet/vk"])?;
98+
/// ```
99+
pub fn run_garaga_command(cfg: &Config, args: &[&str]) -> Result<()> {
100+
let args_vec: Vec<String> = args.iter().map(|s| s.to_string()).collect();
101+
102+
if cfg.verbose && !cfg.quiet {
103+
info!("Running: garaga {}", args_vec.join(" "));
104+
}
105+
106+
// Create command specification for garaga
107+
let spec = CmdSpec::new("garaga".to_string(), args_vec);
108+
109+
// Use the runner to execute the command (handles dry-run automatically)
110+
cfg.runner.run(&spec)
111+
}
112+
113+
/// Run a foundry command with consolidated argument building, logging, and dry-run handling
114+
///
115+
/// This is the primary helper for executing foundry commands consistently across all
116+
/// command modules. It handles:
117+
/// - Verbose logging (when enabled and not quiet)
118+
/// - Dry-run mode (prints command without executing)
119+
/// - Command execution via the configured runner
120+
///
121+
/// # Arguments
122+
/// * `cfg` - The global configuration containing all flags and runner
123+
/// * `command` - The foundry command to run (forge, cast, anvil)
124+
/// * `args` - Arguments to pass to the foundry command
125+
///
126+
/// # Returns
127+
/// * `Result<()>` - Success or error from command execution
128+
///
129+
/// # Example
130+
/// ```ignore
131+
/// // Execute "forge init --force contracts/evm"
132+
/// run_foundry_command(&config, "forge", &["init", "--force", "contracts/evm"])?;
133+
/// ```
134+
pub fn run_foundry_command(cfg: &Config, command: &str, args: &[&str]) -> Result<()> {
135+
let args_vec: Vec<String> = args.iter().map(|s| s.to_string()).collect();
136+
137+
if cfg.verbose && !cfg.quiet {
138+
info!("Running: {} {}", command, args_vec.join(" "));
139+
}
140+
141+
// Create command specification for foundry command
142+
let spec = CmdSpec::new(command.to_string(), args_vec);
143+
144+
// Use the runner to execute the command (handles dry-run automatically)
145+
cfg.runner.run(&spec)
73146
}
74147

75148
/// Run a bb command with consolidated argument building, logging, and dry-run handling

0 commit comments

Comments
 (0)