Skip to content

Commit

Permalink
add JDClient CLI start commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jbesraa committed Aug 19, 2024
1 parent edad21c commit 3cf2618
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
27 changes: 27 additions & 0 deletions stratum-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions stratum-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ clap = { version = "4.5.16", features = ["derive"] }
ext-config = { version = "0.14.0", features = ["toml"], package = "config" }
serde = { version = "1.0.89", default-features = false }
tokio = { version = "1", features = ["full"] }
tracing-subscriber = { version = "0.3" }

translator_sv2 = { path = "../roles/translator" }
jd_client = { path = "../roles/jd-client" }
34 changes: 26 additions & 8 deletions stratum-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct Cli {
enum Commands {
/// Stratum V2 Translator
Translator(RoleArgs),
/// Stratum V2 Job Declarator Client
JDClient(RoleArgs),
}

#[derive(Debug, Args)]
Expand All @@ -32,19 +34,14 @@ enum RoleCommands {
}

fn parse_file<'a, T: serde::Deserialize<'a>>(config_path: &str) -> Option<T> {
let settings = Config::builder()
Config::builder()
.add_source(File::new(config_path, FileFormat::Toml))
.build().ok();
if let Some(settings) = settings {
settings.try_deserialize::<T>().ok()
} else {
None
};
None
.build().ok().and_then(|s| s.try_deserialize::<T>().ok())
}

#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let cli = Cli::parse();
match &cli.command {
Some(Commands::Translator (role_args)) => {
Expand All @@ -68,6 +65,27 @@ async fn main() {
}
}
}
Some(Commands::JDClient (role_args)) => {
match &role_args.command {
Some(RoleCommands::StartLocal) => {
let path = "../roles/jd-client/config-examples/jdc-config-local-example.toml".to_string();
let config: jd_client::proxy_config::ProxyConfig = parse_file(&path).unwrap();
jd_client::JobDeclaratorClient::new(config).start().await;
}
Some(RoleCommands::StartHosted) => {
let path = "../roles/jd-client/config-examples/jdc-config-hosted-example.toml".to_string();
let config: jd_client::proxy_config::ProxyConfig = parse_file(&path).unwrap();
jd_client::JobDeclaratorClient::new(config).start().await;
}
Some(RoleCommands::StartConfig { path }) => {
let config: jd_client::proxy_config::ProxyConfig = parse_file(path).unwrap();
jd_client::JobDeclaratorClient::new(config).start().await;
}
None => {
println!("JDClient No command");
}
}
}
None => {
println!("No command");
}
Expand Down

0 comments on commit 3cf2618

Please sign in to comment.