generated from PlexSheep/rs-base
Compare commits
2 commits
c5790f9d79
...
03a2243a3e
Author | SHA1 | Date | |
---|---|---|---|
03a2243a3e | |||
71f1f2ba08 |
1 changed files with 3 additions and 5 deletions
|
@ -1,8 +1,3 @@
|
|||
//! # numf
|
||||
//!
|
||||
//! This binary should just take any amount of numbers and print them out formatted to some other
|
||||
//! system.
|
||||
|
||||
use std::io::{IsTerminal, Read};
|
||||
use std::process::exit;
|
||||
|
||||
|
@ -17,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(_) => {
|
||||
|
@ -49,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;
|
||||
|
@ -57,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");
|
||||
|
|
Reference in a new issue