mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-26 20:16:34 +00:00
feat: handle standard input "-" (#257)
This commit is contained in:
1 file changed
+21
-15
+21
-15
@@ -284,12 +284,16 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
let mut reader = match &opt.file {
|
let mut reader = match &opt.file {
|
||||||
Some(filename) => {
|
Some(filename) => {
|
||||||
if filename.is_dir() {
|
if filename.as_os_str() == "-" {
|
||||||
bail!("'{}' is a directory.", filename.to_string_lossy());
|
Input::Stdin(stdin.lock())
|
||||||
}
|
} else {
|
||||||
let file = File::open(filename)?;
|
if filename.is_dir() {
|
||||||
|
bail!("'{}' is a directory.", filename.to_string_lossy());
|
||||||
|
}
|
||||||
|
let file = File::open(filename)?;
|
||||||
|
|
||||||
Input::File(file)
|
Input::File(file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => Input::Stdin(stdin.lock()),
|
None => Input::Stdin(stdin.lock()),
|
||||||
};
|
};
|
||||||
@@ -472,17 +476,19 @@ fn run() -> Result<()> {
|
|||||||
let include_mode = match opt.include_mode {
|
let include_mode = match opt.include_mode {
|
||||||
// include mode on
|
// include mode on
|
||||||
true => {
|
true => {
|
||||||
if opt.file.is_some() {
|
if let Some(include_file) = opt.file {
|
||||||
// input from a file
|
// input from a file
|
||||||
IncludeMode::File(
|
if include_file.as_os_str() == "-" {
|
||||||
opt.file
|
IncludeMode::File("stdin".to_string())
|
||||||
.as_ref()
|
} else {
|
||||||
.unwrap()
|
IncludeMode::File(
|
||||||
.file_name()
|
include_file
|
||||||
.and_then(|n| n.to_str())
|
.file_name()
|
||||||
.unwrap_or("file")
|
.and_then(|n| n.to_str())
|
||||||
.to_string(),
|
.unwrap_or("file")
|
||||||
)
|
.to_string(),
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// input from stdin
|
// input from stdin
|
||||||
IncludeMode::Stdin
|
IncludeMode::Stdin
|
||||||
|
|||||||
Reference in new issue
Block a user