You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently attempting to develop a command-line parser using clap.
However, I've encountered difficulty in representing the following behavior:
cargo run -- --port <PORT> --replicaof <MASTER_HOST> <MASTER_PORT>
Here, the <PORT> is expected to be a u16, <MASTER_HOST> is a String, and <MASTER_PORT> is another u16.
Essentially, what I'm seeking is something that looks like this:
#[derive(Parser)]
struct RedisArgs {
/// Set the server's port
#[arg(long, default_value = "6379")]
port: u16,
/// Set server to replica
#[arg(long)]
replicaof: Option<(String ,u16)>,
}
However, I've encountered an issue where clap fails to compile with this structure.
Using Vec as an alternative means all arguments are treated as strings, which is not what I want, especially for the port argument.
Is there a solution to this problem, or must I resort to the Vec method?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm currently attempting to develop a command-line parser using clap.
However, I've encountered difficulty in representing the following behavior:
Here, the
<PORT>
is expected to be au16
,<MASTER_HOST>
is aString
, and<MASTER_PORT>
is anotheru16
.Essentially, what I'm seeking is something that looks like this:
However, I've encountered an issue where clap fails to compile with this structure.
Using Vec as an alternative means all arguments are treated as strings, which is not what I want, especially for the port argument.
Is there a solution to this problem, or must I resort to the Vec method?
Here is the description of the problem: codecrafters: redis: replication-3
Beta Was this translation helpful? Give feedback.
All reactions