Skip to content

Commit

Permalink
Merge pull request #37 from pamburus/release/0.13.0
Browse files Browse the repository at this point in the history
new: Print help and exit if executed without arguments with input from terminal
  • Loading branch information
pamburus authored Nov 26, 2022
2 parents 3ed11c7 + 624055e commit 1baf125
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.12.2"
version = "0.13.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Arc;
// third-party imports
use chrono::{FixedOffset, Local, TimeZone};
use chrono_tz::{Tz, UTC};
use clap::{ArgEnum, Parser};
use clap::{ArgEnum, CommandFactory, Parser};
use itertools::Itertools;
use nu_ansi_term::Color;
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -211,6 +211,7 @@ fn run() -> Result<()> {
let app_dirs = AppDirs::new(Some("hl"), true).unwrap();
let settings = Settings::load(&app_dirs)?;
let opt = Opt::parse();
let stdin_is_atty = || atty::is(atty::Stream::Stdin);
let stdout_is_atty = || atty::is(atty::Stream::Stdout);
let color_supported = if stdout_is_atty() {
if let Err(err) = hl::enable_ansi_support() {
Expand Down Expand Up @@ -321,7 +322,7 @@ fn run() -> Result<()> {
let app = hl::App::new(hl::Options {
theme: Arc::new(theme),
raw_fields: opt.raw_fields,
time_format: time_format,
time_format,
buffer_size,
max_message_size,
concurrency,
Expand All @@ -347,6 +348,10 @@ fn run() -> Result<()> {
})
.collect::<std::io::Result<Vec<_>>>()?;
let mut input: InputStream = if inputs.len() == 0 {
if stdin_is_atty() {
let mut cmd = Opt::command();
return cmd.print_help().map_err(Error::Io);
}
Box::new(std::io::stdin())
} else {
Box::new(ConcatReader::new(inputs.into_iter().map(|x| Ok(x))))
Expand Down

0 comments on commit 1baf125

Please sign in to comment.