Skip to content

Commit

Permalink
Fix argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaum committed Dec 7, 2024
1 parent f447cfb commit c2cd140
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
2 changes: 1 addition & 1 deletion crates/rpc/rpc-common/src/client_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use clap_derive::Parser;
use std::path::PathBuf;

/// Common command line arguments for hosts / clients
#[derive(Parser, Debug)] // requires `derive` feature
#[derive(Clone, Parser, Debug)] // requires `derive` feature
pub struct RpcClientArgs {
#[arg(
long,
Expand Down
14 changes: 8 additions & 6 deletions crates/telnet-host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ mod listen;

#[derive(Parser, Debug)]
struct Args {
#[command(flatten)]
client_args: RpcClientArgs,

#[arg(
long,
value_name = "telnet-address",
Expand All @@ -57,7 +60,6 @@ struct Args {
async fn main() -> Result<(), eyre::Error> {
color_eyre::install()?;
let args: Args = Args::parse();
let client_args: RpcClientArgs = RpcClientArgs::parse();

let main_subscriber = tracing_subscriber::fmt()
.compact()
Expand Down Expand Up @@ -89,8 +91,8 @@ async fn main() -> Result<(), eyre::Error> {

let (mut listeners_server, listeners_channel, listeners) = Listeners::new(
zmq_ctx.clone(),
client_args.rpc_address.clone(),
client_args.events_address.clone(),
args.client_args.rpc_address.clone(),
args.client_args.events_address.clone(),
kill_switch.clone(),
);
let listeners_thread = tokio::spawn(async move {
Expand All @@ -102,14 +104,14 @@ async fn main() -> Result<(), eyre::Error> {
.await
.expect("Unable to start default listener");

let keypair = load_keypair(&client_args.public_key, &client_args.private_key)
let keypair = load_keypair(&args.client_args.public_key, &args.client_args.private_key)
.expect("Unable to load keypair from public and private key files");
let host_token = make_host_token(&keypair, HostType::TCP);

let rpc_client = start_host_session(
host_token.clone(),
zmq_ctx.clone(),
client_args.rpc_address.clone(),
args.client_args.rpc_address.clone(),
kill_switch.clone(),
listeners.clone(),
)
Expand All @@ -120,7 +122,7 @@ async fn main() -> Result<(), eyre::Error> {
rpc_client,
host_token,
zmq_ctx.clone(),
client_args.events_address.clone(),
args.client_args.events_address.clone(),
args.telnet_address.clone(),
kill_switch.clone(),
listeners.clone(),
Expand Down
26 changes: 12 additions & 14 deletions crates/testing/load-tools/src/tx-list-append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ use crate::setup::{
use clap::Parser;
use clap_derive::Parser;
use edn_format::{Keyword, Value};
use eyre::anyhow;
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use moor_values::model::ObjectRef;
use moor_values::{v_int, v_list, List, Obj, Sequence, Symbol, Var, Variant};
use rpc_async_client::pubsub_client::events_recv;
use rpc_async_client::rpc_client::RpcSendClient;
use rpc_async_client::{make_host_token, start_host_session};
use rpc_common::client_args::RpcClientArgs;
use rpc_common::DaemonToClientReply::TaskSubmitted;
use rpc_common::{
load_keypair, AuthToken, ClientEvent, ClientToken, HostClientToDaemonMessage, HostType,
ReplyResult,
load_keypair, AuthToken, ClientToken, HostClientToDaemonMessage, HostType, ReplyResult,
};
use setup::ExecutionContext;
use std::collections::{BTreeMap, HashMap};
Expand All @@ -53,6 +50,9 @@ use uuid::Uuid;

#[derive(Clone, Parser, Debug)]
struct Args {
#[command(flatten)]
client_args: RpcClientArgs,

#[arg(
long,
value_name = "num-users",
Expand Down Expand Up @@ -356,7 +356,6 @@ async fn workload(

async fn list_append_workload(
args: Args,
client_args: RpcClientArgs,
ExecutionContext {
zmq_ctx,
kill_switch,
Expand All @@ -368,19 +367,19 @@ async fn list_append_workload(
client_token,
client_id,
rpc_client,
mut events_sub,
events_sub,
broadcast_sub,
) = create_user_session(
zmq_ctx.clone(),
client_args.rpc_address.clone(),
client_args.events_address.clone(),
args.client_args.rpc_address.clone(),
args.client_args.events_address.clone(),
)
.await?;

{
let kill_switch = kill_switch.clone();
let zmq_ctx = zmq_ctx.clone();
let rpc_address = client_args.rpc_address.clone();
let rpc_address = args.client_args.rpc_address.clone();
let client_id = client_id.clone();

Check warning on line 383 in crates/testing/load-tools/src/tx-list-append.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `Uuid` which implements the `Copy` trait

warning: using `clone` on type `Uuid` which implements the `Copy` trait --> crates/testing/load-tools/src/tx-list-append.rs:383:25 | 383 | let client_id = client_id.clone(); | ^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `client_id` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
let client_token = client_token.clone();
let connection_oid = connection_oid.clone();
Expand Down Expand Up @@ -440,7 +439,7 @@ async fn list_append_workload(
let connection_oid = connection_oid.clone();
let auth_token = auth_token.clone();
let client_token = client_token.clone();
let rpc_address = client_args.rpc_address.clone();
let rpc_address = args.client_args.rpc_address.clone();
let args = args.clone();
let task_results = task_results.clone();
workload_futures.push(workload(
Expand Down Expand Up @@ -613,7 +612,6 @@ async fn list_append_workload(
async fn main() -> Result<(), eyre::Error> {
color_eyre::install().expect("Unable to install color_eyre");
let args: Args = Args::parse();
let client_args: RpcClientArgs = RpcClientArgs::parse();

let main_subscriber = tracing_subscriber::fmt()
.compact()
Expand All @@ -633,7 +631,7 @@ async fn main() -> Result<(), eyre::Error> {
let zmq_ctx = tmq::Context::new();
let kill_switch = Arc::new(AtomicBool::new(false));

let keypair = load_keypair(&client_args.public_key, &client_args.private_key)
let keypair = load_keypair(&args.client_args.public_key, &args.client_args.private_key)
.expect("Unable to load keypair from public and private key files");
let host_token = make_host_token(&keypair, HostType::TCP);

Expand All @@ -642,7 +640,7 @@ async fn main() -> Result<(), eyre::Error> {
let _rpc_client = start_host_session(
host_token.clone(),
zmq_ctx.clone(),
client_args.rpc_address.clone(),
args.client_args.rpc_address.clone(),
kill_switch.clone(),
listeners.clone(),
)
Expand All @@ -653,7 +651,7 @@ async fn main() -> Result<(), eyre::Error> {
zmq_ctx,
kill_switch: kill_switch.clone(),
};
list_append_workload(args, client_args, exec_context).await?;
list_append_workload(args, exec_context).await?;

kill_switch.store(true, std::sync::atomic::Ordering::Relaxed);
Ok(())
Expand Down
19 changes: 10 additions & 9 deletions crates/testing/load-tools/src/verb-dispatch-load-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ use uuid::Uuid;

#[derive(Clone, Parser, Debug)]
struct Args {
#[command(flatten)]
client_args: RpcClientArgs,

#[arg(
long,
value_name = "num-concurrent-workloads",
Expand Down Expand Up @@ -173,7 +176,6 @@ async fn workload(

async fn load_test_workload(
args: Args,
client_args: RpcClientArgs,
ExecutionContext {
zmq_ctx,
kill_switch,
Expand All @@ -189,15 +191,15 @@ async fn load_test_workload(
broadcast_sub,
) = create_user_session(
zmq_ctx.clone(),
client_args.rpc_address.clone(),
client_args.events_address.clone(),
args.client_args.rpc_address.clone(),
args.client_args.events_address.clone(),
)
.await?;

{
let kill_switch = kill_switch.clone();
let zmq_ctx = zmq_ctx.clone();
let rpc_address = client_args.rpc_address.clone();
let rpc_address = args.client_args.rpc_address.clone();
let client_id = client_id.clone();

Check warning on line 203 in crates/testing/load-tools/src/verb-dispatch-load-test.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `Uuid` which implements the `Copy` trait

warning: using `clone` on type `Uuid` which implements the `Copy` trait --> crates/testing/load-tools/src/verb-dispatch-load-test.rs:203:25 | 203 | let client_id = client_id.clone(); | ^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `client_id` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
let client_token = client_token.clone();
let connection_oid = connection_oid.clone();
Expand Down Expand Up @@ -261,7 +263,7 @@ async fn load_test_workload(
let connection_oid = connection_oid.clone();
let auth_token = auth_token.clone();
let client_token = client_token.clone();
let rpc_address = client_args.rpc_address.clone();
let rpc_address = args.client_args.rpc_address.clone();
let args = args.clone();
let task_results = task_results.clone();
workload_futures.push(workload(
Expand Down Expand Up @@ -309,7 +311,6 @@ async fn load_test_workload(
async fn main() -> Result<(), eyre::Error> {
color_eyre::install().expect("Unable to install color_eyre");
let args: Args = Args::parse();
let client_args: RpcClientArgs = RpcClientArgs::parse();

let main_subscriber = tracing_subscriber::fmt()
.compact()
Expand All @@ -329,7 +330,7 @@ async fn main() -> Result<(), eyre::Error> {
let zmq_ctx = tmq::Context::new();
let kill_switch = Arc::new(AtomicBool::new(false));

let keypair = load_keypair(&client_args.public_key, &client_args.private_key)
let keypair = load_keypair(&args.client_args.public_key, &args.client_args.private_key)
.expect("Unable to load keypair from public and private key files");
let host_token = make_host_token(&keypair, HostType::TCP);

Expand All @@ -338,7 +339,7 @@ async fn main() -> Result<(), eyre::Error> {
let _rpc_client = start_host_session(
host_token.clone(),
zmq_ctx.clone(),
client_args.rpc_address.clone(),
args.client_args.rpc_address.clone(),
kill_switch.clone(),
listeners.clone(),
)
Expand All @@ -350,7 +351,7 @@ async fn main() -> Result<(), eyre::Error> {
kill_switch: kill_switch.clone(),
};

load_test_workload(args, client_args, exec_context).await?;
load_test_workload(args, exec_context).await?;

kill_switch.store(true, std::sync::atomic::Ordering::Relaxed);
Ok(())
Expand Down
14 changes: 8 additions & 6 deletions crates/web-host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ use tracing::{info, warn};

#[derive(Parser, Debug)]
struct Args {
#[command(flatten)]
client_args: RpcClientArgs,

#[arg(
long,
value_name = "listen-address",
Expand Down Expand Up @@ -219,7 +222,6 @@ fn mk_routes(web_host: WebHost) -> eyre::Result<Router> {
async fn main() -> Result<(), eyre::Error> {
color_eyre::install()?;
let args: Args = Args::parse();
let client_args: RpcClientArgs = RpcClientArgs::parse();

let main_subscriber = tracing_subscriber::fmt()
.compact()
Expand All @@ -239,16 +241,16 @@ async fn main() -> Result<(), eyre::Error> {

let kill_switch = Arc::new(AtomicBool::new(false));

let keypair = load_keypair(&client_args.public_key, &client_args.private_key)
let keypair = load_keypair(&args.client_args.public_key, &args.client_args.private_key)
.expect("Unable to load keypair from public and private key files");
let host_token = make_host_token(&keypair, HostType::TCP);

let zmq_ctx = tmq::Context::new();

let (mut listeners_server, listeners_channel, listeners) = Listeners::new(
zmq_ctx.clone(),
client_args.rpc_address.clone(),
client_args.events_address.clone(),
args.client_args.rpc_address.clone(),
args.client_args.events_address.clone(),
kill_switch.clone(),
);
let listeners_thread = tokio::spawn(async move {
Expand All @@ -258,7 +260,7 @@ async fn main() -> Result<(), eyre::Error> {
let rpc_client = start_host_session(
host_token.clone(),
zmq_ctx.clone(),
client_args.rpc_address.clone(),
args.client_args.rpc_address.clone(),
kill_switch.clone(),
listeners.clone(),
)
Expand All @@ -274,7 +276,7 @@ async fn main() -> Result<(), eyre::Error> {
rpc_client,
host_token,
zmq_ctx.clone(),
client_args.events_address.clone(),
args.client_args.events_address.clone(),
args.listen_address.clone(),
kill_switch.clone(),
listeners.clone(),
Expand Down

0 comments on commit c2cd140

Please sign in to comment.