mirror of
https://github.com/n0-computer/iroh.git
synced 2026-12-04 00:01:26 +00:00
## Description
Modernizes Clap v4 usage in iroh-dns-server
- Replaces legacy `#[clap(...)]` attributes with `#[arg(...)]` /
`#[command(...)]`
- Uses `Subcommand` for subcommand enums instead of `Parser`
- Keeps CLI behavior otherwise unchanged
## Change checklist
- [x] Self-review
- [x] Tests if relevant
- [x] This PR was created by a human that thought critically about the
proposed change and wrote an as clear and concise description as
they could
- [x] This PR isn't slop, and is carefully crafted to do have the
intented effect
Co-authored-by: Floris Bruynooghe <flub@n0.computer>
34 lines
825 B
Rust
34 lines
825 B
Rust
use std::str::FromStr;
|
|
|
|
use clap::{Parser, Subcommand};
|
|
use iroh::EndpointId;
|
|
use n0_error::{Result, StdResultExt};
|
|
|
|
#[derive(Debug, Parser)]
|
|
#[command(version, about)]
|
|
struct Cli {
|
|
#[command(subcommand)]
|
|
command: Command,
|
|
}
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
enum Command {
|
|
EndpointToPkarr { endpoint_id: String },
|
|
PkarrToEndpoint { z32_pubkey: String },
|
|
}
|
|
|
|
fn main() -> Result<()> {
|
|
let args = Cli::parse();
|
|
match args.command {
|
|
Command::EndpointToPkarr { endpoint_id } => {
|
|
let endpoint_id = EndpointId::from_str(&endpoint_id)?;
|
|
println!("{}", endpoint_id.to_z32())
|
|
}
|
|
Command::PkarrToEndpoint { z32_pubkey } => {
|
|
let endpoint_id = EndpointId::from_z32(&z32_pubkey).anyerr()?;
|
|
println!("{endpoint_id}")
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|