Created
September 15, 2023 21:51
-
-
Save maciektr/6b6c18a358b5792912bc0d0261ef3ac2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anyhow::Result; | |
use clap::{Parser, Subcommand}; | |
#[derive(Parser, Clone, Debug)] | |
struct Args { | |
/// Subcommand and its arguments. | |
#[command(subcommand)] | |
pub command: Command, | |
} | |
#[derive(Subcommand, Clone, Debug)] | |
pub enum Command { | |
HangOnTcp(HangOnTcpArgs), | |
} | |
#[derive(Parser, Clone, Debug)] | |
pub struct HangOnTcpArgs { | |
#[arg(short, long)] | |
address: String, | |
} | |
fn main() { | |
let args: Args = Args::parse(); | |
let result = match args.command { | |
Command::HangOnTcp(args) => hang_on_tcp(args), | |
}; | |
result.unwrap(); | |
} | |
fn hang_on_tcp(args: HangOnTcpArgs) -> Result<()> { | |
use std::io::Read; | |
use std::net::TcpStream; | |
let address: &str = args.address.as_ref(); | |
let mut socket = TcpStream::connect(address).unwrap(); | |
let _ = socket.read(&mut [0; 10]); | |
panic!("that read should never return"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment