forked from mars/breed
Merge pull request 'Handling redirects/pipes and no stdin' (#4) from emma/breed:arg-parsing into main
Reviewed-on: mars/breed#4
This commit is contained in:
commit
9c633b4c72
|
@ -62,6 +62,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arg",
|
"arg",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
|
"libc",
|
||||||
"ropey",
|
"ropey",
|
||||||
"yacexits",
|
"yacexits",
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,5 +7,6 @@ license = "AGPL-3.0-or-later"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
arg = "0.4.1"
|
arg = "0.4.1"
|
||||||
crossterm = "0.26"
|
crossterm = "0.26"
|
||||||
|
libc = "0.2.141"
|
||||||
ropey = "1.6"
|
ropey = "1.6"
|
||||||
yacexits = "0.1.5"
|
yacexits = "0.1.5"
|
||||||
|
|
|
@ -451,7 +451,12 @@ fn main() -> Result<()> {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
match argv.get(1).map(|s| s.as_str()) {
|
match argv.get(1).map(|s| s.as_str()) {
|
||||||
Some("-") | None => unsafe { File::from_raw_fd(0) }, // stdin as a file
|
Some("-") | None => {
|
||||||
|
let stdin = 0; // get stdin as a file descriptor
|
||||||
|
if unsafe { libc::isatty(stdin) } == 0 {
|
||||||
|
unsafe { File::from_raw_fd(stdin) }
|
||||||
|
} else { File::open("/dev/null").unwrap() }
|
||||||
|
},
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
std::fs::File::open(path).unwrap_or_else(|_| {
|
std::fs::File::open(path).unwrap_or_else(|_| {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
|
Loading…
Reference in New Issue