Import Path in main.rs
This commit is contained in:
parent
6f81bab277
commit
5bf1212b2a
46
src/main.rs
46
src/main.rs
|
@ -20,15 +20,10 @@
|
|||
use std::{
|
||||
env::args,
|
||||
ffi::OsString,
|
||||
fs::{ File, OpenOptions },
|
||||
io::{
|
||||
Read,
|
||||
stdout,
|
||||
Stdout,
|
||||
Write,
|
||||
},
|
||||
fs::{File, OpenOptions},
|
||||
io::{stdout, Read, Stdout, Write},
|
||||
os::fd::FromRawFd,
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
|
@ -358,22 +353,17 @@ impl State {
|
|||
handle = match command_parts.get(1) {
|
||||
Some(part) => OsString::from(part),
|
||||
None => {
|
||||
return Err(
|
||||
format!("{}: No file name.", command)
|
||||
);
|
||||
},
|
||||
return Err(format!("{}: No file name.", command));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
self.write_buffer(handle).map_err(|err| {
|
||||
format!("{}", err)
|
||||
})?;
|
||||
},
|
||||
self.write_buffer(handle)
|
||||
.map_err(|err| format!("{}", err))?;
|
||||
}
|
||||
command => {
|
||||
return Err(
|
||||
format!("{}: Unrecognized command.", command)
|
||||
);
|
||||
},
|
||||
return Err(format!("{}: Unrecognized command.", command));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -420,13 +410,13 @@ fn main() -> Result<()> {
|
|||
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() }
|
||||
},
|
||||
} else {
|
||||
File::open("/dev/null").unwrap()
|
||||
}
|
||||
}
|
||||
Some(path) => {
|
||||
let input_file = Path::new(path);
|
||||
file_name = Some(OsString::from(
|
||||
input_file.clone().display().to_string()
|
||||
));
|
||||
file_name = Some(OsString::from(input_file.clone().display().to_string()));
|
||||
|
||||
File::open(input_file).unwrap_or_else(|_| {
|
||||
let mut err = String::new();
|
||||
|
@ -438,8 +428,10 @@ fn main() -> Result<()> {
|
|||
eprintln!("{}: {}: {}", argv[0], path, err);
|
||||
exit(EX_UNAVAILABLE);
|
||||
})
|
||||
},
|
||||
}.read_to_end(&mut buf).unwrap();
|
||||
}
|
||||
}
|
||||
.read_to_end(&mut buf)
|
||||
.unwrap();
|
||||
|
||||
let text = String::from_utf8(buf).unwrap_or_else(|_| {
|
||||
eprintln!(
|
||||
|
|
Loading…
Reference in New Issue