Skip to content

Commit

Permalink
Merge pull request #125 from HerodotusDev/cli-fix
Browse files Browse the repository at this point in the history
fix: cli env to be compatible with legacy
  • Loading branch information
rkdud007 authored Aug 19, 2024
2 parents 36913aa + 7fb17d3 commit a18fde4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use hdp::{
TaskEnvelope,
},
};
use tracing::info;
use tracing::{debug, info};
use tracing_subscriber::{EnvFilter, FmtSubscriber};

pub async fn hdp_cli_run() -> anyhow::Result<()> {
Expand Down Expand Up @@ -53,7 +53,7 @@ fn init_cli() -> Result<HDPCli> {
.with_env_filter(EnvFilter::new(&rust_log))
.finish();
tracing::subscriber::set_global_default(subscriber).expect("Failed to set subscriber");
info!("running on log level: {}", rust_log);
debug!("running on log level: {}", rust_log);
let cli = HDPCli::parse();
Ok(cli)
}
Expand All @@ -62,7 +62,7 @@ pub async fn module_entry_run(args: RunModuleArgs) -> Result<()> {
let config = hdp_run::HdpRunConfig::init(
args.rpc_url,
args.chain_id,
Some(args.dry_run_cairo_file),
args.dry_run_cairo_file,
args.sound_run_cairo_file,
args.preprocessor_output_file,
args.save_fetch_keys_file,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct RunArgs {

/// Path to save output file after pre-processing.
#[arg(short, long)]
pub preprocessor_output_file: PathBuf,
pub preprocessor_output_file: Option<PathBuf>,

/// hdp cairo compiled program. main entry point
#[arg(long)]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/run_datalake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct RunDatalakeArgs {
///
/// This will trigger pre-processing step
#[arg(short, long)]
pub preprocessor_output_file: PathBuf,
pub preprocessor_output_file: Option<PathBuf>,

/// hdp cairo compiled program. main entry point
#[arg(long)]
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/run_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ pub struct RunModuleArgs {
/// dry run contract bootloader program.
/// only used for module task
#[arg(long)]
pub dry_run_cairo_file: PathBuf,
pub dry_run_cairo_file: Option<PathBuf>,

/// Path to save output file after pre-processing.
///
/// This will trigger pre-processing step
#[arg(short, long)]
pub preprocessor_output_file: PathBuf,
pub preprocessor_output_file: Option<PathBuf>,

/// hdp cairo compiled program. main entry point
#[arg(long)]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ pub async fn run_interactive() -> anyhow::Result<()> {
chain_id,
None,
None,
cairo_input,
Some(cairo_input),
None,
Some(output_file),
Some(pie_file),
Expand Down
30 changes: 18 additions & 12 deletions hdp/src/hdp_run.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use alloy::primitives::ChainId;
use anyhow::Result;
use reqwest::Url;
use std::{env, fs, path::PathBuf};
use tracing::{debug, info};

#[cfg(feature = "test_utils")]
use crate::constant::DEFAULT_PREPROCESSOR_OUTPUT_FILE;

use crate::{
constant::{DEFAULT_DRY_CAIRO_RUN_CAIRO_FILE, DEFAULT_SOUND_CAIRO_RUN_CAIRO_FILE},
constant::{
DEFAULT_DRY_CAIRO_RUN_CAIRO_FILE, DEFAULT_PREPROCESSOR_OUTPUT_FILE,
DEFAULT_SOUND_CAIRO_RUN_CAIRO_FILE,
},
preprocessor::{compile::config::CompilerConfig, PreProcessor},
primitives::{processed_types::cairo_format::AsCairoFormat, task::TaskEnvelope},
processor::Processor,
provider::evm::config::EvmProviderConfig,
};
use alloy::primitives::ChainId;
use anyhow::Result;
use reqwest::Url;
use std::{env, fs, path::PathBuf};
use tracing::{debug, info};

/// HdpRunConfig for the CLI
#[derive(Debug)]
Expand Down Expand Up @@ -48,7 +47,7 @@ impl HdpRunConfig {
cli_chain_id: Option<ChainId>,
cli_dry_run_cairo_file: Option<PathBuf>,
cli_sound_run_cairo_file: Option<PathBuf>,
cli_pre_processor_output_file: PathBuf,
cli_pre_processor_output_file: Option<PathBuf>,
cli_save_fetch_keys_file: Option<PathBuf>,
cli_processor_output_file: Option<PathBuf>,
cli_cairo_pie_file: Option<PathBuf>,
Expand All @@ -71,6 +70,13 @@ impl HdpRunConfig {
.expect("RPC_CHUNK_SIZE must be a number");
let save_fetch_keys_file: Option<PathBuf> = cli_save_fetch_keys_file
.or_else(|| env::var("SAVE_FETCH_KEYS_FILE").ok().map(PathBuf::from));
let pre_processor_output_file: PathBuf =
cli_pre_processor_output_file.unwrap_or_else(|| {
env::var("DRY_RUN_CAIRO_PATH")
.unwrap_or_else(|_| DEFAULT_PREPROCESSOR_OUTPUT_FILE.to_string())
.parse()
.expect("DRY_RUN_CAIRO_PATH must be a path to a cairo file")
});
let dry_run_cairo_path: PathBuf = cli_dry_run_cairo_file.unwrap_or_else(|| {
env::var("DRY_RUN_CAIRO_PATH")
.unwrap_or_else(|_| DEFAULT_DRY_CAIRO_RUN_CAIRO_FILE.to_string())
Expand All @@ -92,7 +98,7 @@ impl HdpRunConfig {
},
dry_run_program_path: dry_run_cairo_path,
sound_run_program_path: sound_run_cairo_path,
pre_processor_output_file: cli_pre_processor_output_file,
pre_processor_output_file,
save_fetch_keys_file,
processor_output_file: cli_processor_output_file,
cairo_pie_file: cli_cairo_pie_file,
Expand Down

0 comments on commit a18fde4

Please sign in to comment.