mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-02 19:21:37 +00:00
*: Change structopt to native clap derive implementations (#2600)
Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
@ -28,7 +28,7 @@ prost = "0.10"
|
||||
[dev-dependencies]
|
||||
async-std = { version = "1.10", features = ["attributes"] }
|
||||
env_logger = "0.9"
|
||||
structopt = "0.3"
|
||||
clap = {version = "3.1.6", features = ["derive"]}
|
||||
|
||||
|
||||
[dev-dependencies.libp2p]
|
||||
|
@ -29,6 +29,7 @@
|
||||
//! ```
|
||||
//! The `listen-port` parameter is optional and allows to set a fixed port at which the local client should listen.
|
||||
|
||||
use clap::Parser;
|
||||
use futures::prelude::*;
|
||||
use libp2p::autonat;
|
||||
use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent};
|
||||
@ -38,18 +39,17 @@ use libp2p::{identity, Multiaddr, NetworkBehaviour, PeerId};
|
||||
use std::error::Error;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::time::Duration;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(name = "libp2p autonat")]
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(name = "libp2p autonat")]
|
||||
struct Opt {
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
listen_port: Option<u16>,
|
||||
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
server_address: Multiaddr,
|
||||
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
server_peer_id: PeerId,
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ struct Opt {
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
env_logger::init();
|
||||
|
||||
let opt = Opt::from_args();
|
||||
let opt = Opt::parse();
|
||||
|
||||
let local_key = identity::Keypair::generate_ed25519();
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
|
@ -26,6 +26,7 @@
|
||||
//! ```
|
||||
//! The `listen-port` parameter is optional and allows to set a fixed port at which the local peer should listen.
|
||||
|
||||
use clap::Parser;
|
||||
use futures::prelude::*;
|
||||
use libp2p::autonat;
|
||||
use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent};
|
||||
@ -34,12 +35,11 @@ use libp2p::swarm::{Swarm, SwarmEvent};
|
||||
use libp2p::{identity, Multiaddr, NetworkBehaviour, PeerId};
|
||||
use std::error::Error;
|
||||
use std::net::Ipv4Addr;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(name = "libp2p autonat")]
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(name = "libp2p autonat")]
|
||||
struct Opt {
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
listen_port: Option<u16>,
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ struct Opt {
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
env_logger::init();
|
||||
|
||||
let opt = Opt::from_args();
|
||||
let opt = Opt::parse();
|
||||
|
||||
let local_key = identity::Keypair::generate_ed25519();
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
|
@ -36,4 +36,4 @@ libp2p-plaintext = { path = "../../transports/plaintext" }
|
||||
libp2p-relay = { path = "../relay" }
|
||||
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||
rand = "0.7"
|
||||
structopt = "0.3.21"
|
||||
clap = {version = "3.1.6", features = ["derive"]}
|
||||
|
@ -18,6 +18,7 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
use clap::Parser;
|
||||
use futures::executor::block_on;
|
||||
use futures::future::FutureExt;
|
||||
use futures::stream::StreamExt;
|
||||
@ -39,29 +40,28 @@ use std::convert::TryInto;
|
||||
use std::error::Error;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::str::FromStr;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(name = "libp2p DCUtR client")]
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(name = "libp2p DCUtR client")]
|
||||
struct Opts {
|
||||
/// The mode (client-listen, client-dial).
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
mode: Mode,
|
||||
|
||||
/// Fixed value to generate deterministic peer id.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
secret_key_seed: u8,
|
||||
|
||||
/// The listening address
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
relay_address: Multiaddr,
|
||||
|
||||
/// Peer ID of the remote peer to hole punch to.
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
remote_peer_id: Option<PeerId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt, PartialEq)]
|
||||
#[derive(Debug, Parser, PartialEq)]
|
||||
enum Mode {
|
||||
Dial,
|
||||
Listen,
|
||||
@ -81,7 +81,7 @@ impl FromStr for Mode {
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
env_logger::init();
|
||||
|
||||
let opts = Opts::from_args();
|
||||
let opts = Opts::parse();
|
||||
|
||||
let local_key = generate_ed25519(opts.secret_key_seed);
|
||||
let local_peer_id = PeerId::from(local_key.public());
|
||||
|
@ -41,4 +41,4 @@ libp2p-ping = { path = "../ping" }
|
||||
libp2p-plaintext = { path = "../../transports/plaintext" }
|
||||
libp2p-yamux = { path = "../../muxers/yamux" }
|
||||
quickcheck = "1"
|
||||
structopt = "0.3.21"
|
||||
clap = {version = "3.1.6", features = ["derive"]}
|
||||
|
@ -19,6 +19,7 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
use clap::Parser;
|
||||
use futures::executor::block_on;
|
||||
use futures::stream::StreamExt;
|
||||
use libp2p::core::upgrade;
|
||||
@ -33,12 +34,11 @@ use libp2p::{identity, NetworkBehaviour, PeerId};
|
||||
use libp2p::{noise, Multiaddr};
|
||||
use std::error::Error;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
use structopt::StructOpt;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
env_logger::init();
|
||||
|
||||
let opt = Opt::from_args();
|
||||
let opt = Opt::parse();
|
||||
println!("opt: {:?}", opt);
|
||||
|
||||
// Create a static known PeerId based on given secret
|
||||
@ -135,18 +135,18 @@ fn generate_ed25519(secret_key_seed: u8) -> identity::Keypair {
|
||||
identity::Keypair::Ed25519(secret_key.into())
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(name = "libp2p relay")]
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(name = "libp2p relay")]
|
||||
struct Opt {
|
||||
/// Determine if the relay listen on ipv6 or ipv4 loopback address. the default is ipv4
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
use_ipv6: Option<bool>,
|
||||
|
||||
/// Fixed value to generate deterministic peer id
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
secret_key_seed: u8,
|
||||
|
||||
/// The port used to listen on all interfaces
|
||||
#[structopt(long)]
|
||||
#[clap(long)]
|
||||
port: u16,
|
||||
}
|
||||
|
Reference in New Issue
Block a user