Files
iroh/iroh-dns-server/examples/convert.rs
oriel haimandFloris Bruynooghe 12cd62b5d1 refactor(iroh-dns-server): update clap usage to modern v4 APIs (#4567)
## 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>
2026-10-02 13:27:52 +00:00

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(())
}