From 03a2243a3e1a6b8ebbc6bd5362ca8117b3179648 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 23 May 2024 13:29:03 +0200 Subject: [PATCH] docs(main): add a few explanatory comments to main --- src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.rs b/src/main.rs index a68bad6..152543b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ fn main() -> anyhow::Result<()> { let mut options = FormatOptions::parse(); let mut stdin_nums = Vec::new(); let stdin = std::io::stdin(); + // only accept numbers from stdin if the stdin is not an interactive terminal if !stdin.is_terminal() { match stdin.lock().read_to_end(&mut stdin_nums) { Ok(_) => { @@ -44,6 +45,7 @@ fn main() -> anyhow::Result<()> { }; } + // add random numbers to the number list, according to how many are requested if options.rand() > 0 { use rand::prelude::*; let mut rand = rand::rngs::OsRng; @@ -52,6 +54,7 @@ fn main() -> anyhow::Result<()> { } } + // exit with error if no numbers are to be formatted if options.numbers().is_empty() { eprintln!("{}", FormatOptions::command().render_usage()); eprintln!("no numbers have been provided");