Skip to content

Commit

Permalink
feat: expose mode to the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
dndll committed May 14, 2024
1 parent fe863a4 commit 8732f4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bin/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap;
use clap::{command, Parser};
use near_da_http_api_data::ConfigureClientRequest;
use near_da_primitives::Mode;
use near_da_rpc::near::config::Config;
use near_da_rpc::near::Client;
use near_da_rpc::{CryptoHash, DataAvailability};
Expand All @@ -20,6 +21,8 @@ struct Args {
config: Option<String>,
#[command(subcommand)]
command: Commands,
#[clap(short, long)]
mode: Option<Mode>,
}
struct AppState {
client: Option<Client>,
Expand All @@ -37,7 +40,7 @@ fn config_request_to_config(request: ConfigureClientRequest) -> Result<Config, a
namespace: request
.namespace
.map(|ns| near_da_primitives::Namespace::new(ns.version, ns.id)),
mode: Default::default(),
mode: request.mode.unwrap_or_default(),
})
}

Expand Down
11 changes: 11 additions & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ pub enum Mode {
Pessimistic,
}

impl From<&str> for Mode {
fn from(s: &str) -> Self {
match s.to_lowercase().as_str() {
"optimistic" => Mode::Optimistic,
"standard" => Mode::Standard,
"pessimistic" => Mode::Pessimistic,
_ => Mode::Pessimistic,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 8732f4f

Please sign in to comment.