Created
June 3, 2023 18:52
-
-
Save nhalase/b90cc32524746afbf33a218f838dd644 to your computer and use it in GitHub Desktop.
Rust echo
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 clap::Parser; | |
/// Rust echo | |
#[derive(Parser, Debug)] | |
#[command()] | |
struct Args { | |
/// Do not print the trailing newline character. | |
#[arg(short, num_args(0), required(false), default_value_t = false)] | |
no_newline: bool, | |
/// The parameters to echo back to STDOUT | |
#[arg(required(false), default_value = "", trailing_var_arg = true)] | |
remaining: Vec<String>, | |
} | |
fn main() { | |
let args = Args::parse(); | |
if args.no_newline { | |
print!("{}", args.remaining.join(" ")); | |
} else { | |
println!("{}", args.remaining.join(" ")); | |
} | |
std::process::exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment