foundry_cli/opts/build/
mod.rsuse clap::Parser;
use foundry_compilers::artifacts::{output_selection::ContractOutputSelection, EvmVersion};
use serde::Serialize;
mod core;
pub use self::core::CoreBuildArgs;
mod paths;
pub use self::paths::ProjectPathsArgs;
#[derive(Clone, Debug, Default, Serialize, Parser)]
#[command(next_help_heading = "Compiler options")]
pub struct CompilerArgs {
#[arg(long, help_heading = "Compiler options")]
#[serde(skip)]
pub ast: bool,
#[arg(long, value_name = "VERSION")]
#[serde(skip_serializing_if = "Option::is_none")]
pub evm_version: Option<EvmVersion>,
#[arg(long, default_missing_value="true", num_args = 0..=1)]
#[serde(skip)]
pub optimize: Option<bool>,
#[arg(long, value_name = "RUNS")]
#[serde(skip_serializing_if = "Option::is_none")]
pub optimizer_runs: Option<usize>,
#[arg(long, num_args(1..), value_name = "SELECTOR")]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub extra_output: Vec<ContractOutputSelection>,
#[arg(long, num_args(1..), value_name = "SELECTOR")]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub extra_output_files: Vec<ContractOutputSelection>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn can_parse_evm_version() {
let args: CompilerArgs =
CompilerArgs::parse_from(["foundry-cli", "--evm-version", "london"]);
assert_eq!(args.evm_version, Some(EvmVersion::London));
}
#[test]
fn can_parse_extra_output() {
let args: CompilerArgs =
CompilerArgs::parse_from(["foundry-cli", "--extra-output", "metadata", "ir-optimized"]);
assert_eq!(
args.extra_output,
vec![ContractOutputSelection::Metadata, ContractOutputSelection::IrOptimized]
);
}
#[test]
fn can_parse_extra_output_files() {
let args: CompilerArgs = CompilerArgs::parse_from([
"foundry-cli",
"--extra-output-files",
"metadata",
"ir-optimized",
]);
assert_eq!(
args.extra_output_files,
vec![ContractOutputSelection::Metadata, ContractOutputSelection::IrOptimized]
);
}
}