Skip to content

Commit 89b00cf

Browse files
committed
feat: add TapeConfig in main.rs and cli.rs
> loadup tape.toml and pass the configs to cli > remove the default `l` option for cluster > add condition to override cluster (rpc_url) with options in cli > if options for clusters are not used in cli, rpc_url from tape.tomlwill be used
1 parent 5e17a95 commit 89b00cf

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cli/src/cli.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::path::PathBuf;
1010
use std::sync::Arc;
1111

1212
use crate::keypair::{get_keypair_path, get_payer};
13+
use crate::config::TapeConfig;
1314

1415
#[derive(Parser)]
1516
#[command(
@@ -28,11 +29,10 @@ pub struct Cli {
2829
#[arg(
2930
short = 'u',
3031
long = "cluster",
31-
default_value = "l",
3232
global = true,
3333
help = "Cluster to use: l (localnet), m (mainnet), d (devnet), t (testnet),\n or a custom RPC URL"
3434
)]
35-
pub cluster: Cluster,
35+
pub cluster: Option<Cluster>,
3636

3737
#[arg(short = 'v', long = "verbose", help = "Print verbose output", global = true)]
3838
pub verbose: bool,
@@ -239,8 +239,12 @@ pub struct Context {
239239
}
240240

241241
impl Context{
242-
pub fn try_build(cli:&Cli) -> Result<Self> {
243-
let rpc_url = cli.cluster.rpc_url();
242+
pub fn try_build(cli:&Cli, config: &TapeConfig) -> Result<Self> {
243+
let rpc_url = if let Some(cluster) = &cli.cluster {
244+
cluster.rpc_url()
245+
} else {
246+
config.solana.rpc_url.to_string()
247+
};
244248
let rpc = Arc::new(
245249
RpcClient::new_with_commitment(rpc_url.clone(),
246250
CommitmentConfig::finalized())

cli/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod keypair;
33
mod log;
44
mod commands;
55
mod utils;
6+
mod config;
67

78

89
use anyhow::{Ok, Result};
@@ -13,6 +14,7 @@ use env_logger::{self, Env};
1314
use tape_network::store::TapeStore;
1415

1516
use crate::cli::Context;
17+
use crate::config::TapeConfig;
1618

1719

1820
fn main() -> Result<()>{
@@ -38,8 +40,12 @@ async fn run_tape_cli() -> Result<()> {
3840

3941
let cli = Cli::parse();
4042

43+
let config = TapeConfig::load().unwrap_or_else(|_| {
44+
log::print_info("tape.toml not found, creating default configuration");
45+
TapeConfig::create_default().expect("Failed to create default config")
46+
});
4147

42-
let context = Context::try_build(&cli)?;
48+
let context = Context::try_build(&cli, &config)?;
4349

4450
match cli.command {
4551
Commands::Init {} |

0 commit comments

Comments
 (0)