Skip to content

Commit

Permalink
Added support for receiving from a pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickTulskie committed Jan 27, 2023
1 parent 75f9cfc commit 14ba428
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
54 changes: 52 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dfang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ edition = "2021"
[dependencies]
regex = "1"
lazy_static = "1"
atty = "0.2.*"
14 changes: 13 additions & 1 deletion dfang/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use lazy_static::lazy_static;
use regex::Regex;
use std::env;
use std::io;
use std::io::Read;
extern crate atty;

lazy_static! {
// Replacers
Expand All @@ -20,7 +23,16 @@ fn main() {
let args: Vec<String> = env::args().collect();

if args.len() < 2 {
help();
let mut input = String::new();
if !atty::is(atty::Stream::Stdin) {
// read input from pipe
io::stdin().read_to_string(&mut input).unwrap();
for line in input.lines() {
println!("{}", defang(line));
}
} else {
help();
}
} else {
for i in 1..args.len() {
println!("{}", defang(&args[i]));
Expand Down
1 change: 1 addition & 0 deletions rfang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ edition = "2021"
[dependencies]
regex = "1"
lazy_static = "1"
atty = "0.2.*"
14 changes: 13 additions & 1 deletion rfang/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use lazy_static::lazy_static;
use regex::Regex;
use std::env;
use std::io;
use std::io::Read;
extern crate atty;

lazy_static! {
// Replacers
Expand All @@ -15,7 +18,16 @@ fn main() {
let args: Vec<String> = env::args().collect();

if args.len() < 2 {
help();
let mut input = String::new();
if !atty::is(atty::Stream::Stdin) {
// read input from pipe
io::stdin().read_to_string(&mut input).unwrap();
for line in input.lines() {
println!("{}", refang(line));
}
} else {
help();
}
} else {
for i in 1..args.len() {
println!("{}", refang(&args[i]));
Expand Down

0 comments on commit 14ba428

Please sign in to comment.