Skip to content

Commit

Permalink
By default, only report progress when stderr is a terminal
Browse files Browse the repository at this point in the history
Can be overridden by --progress=[true/false/auto]. Previous
option --quiet hidden, but kept for compatibility.
  • Loading branch information
th1000s committed Jan 14, 2025
1 parent a514045 commit 4305be2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 10 additions & 2 deletions fclones/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,16 @@ const fn after_help() -> &'static str {
#[derive(clap::Parser, Debug)]
#[command(about, author, version, after_help = after_help(), max_term_width = 100)]
pub struct Config {
/// Suppress progress reporting
#[arg(short('q'), long)]
/// Override progress reporting, by default (=auto) only report when stderr is a terminal.
/// Possible values: true, false, auto.
#[arg(long, value_name = "VAL", require_equals = true,
value_parser(["auto", "true", "false"]), default_value = "auto",
hide_possible_values = true, hide_default_value = true)]
pub progress: String,

// compatibility with fclones <= 0.34, overrides --progress
#[arg(short('q'), long, hide = true)]
pub quiet: bool,

/// Find files
Expand Down
11 changes: 7 additions & 4 deletions fclones/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::ffi::{OsStr, OsString};
use std::fs::File;
use std::io::{stdin, Write};
use std::io::{stderr, stdin, IsTerminal, Write};
use std::process::exit;
use std::sync::Arc;
use std::{fs, io};
Expand Down Expand Up @@ -251,9 +251,12 @@ fn main() {
}

let mut log = StdLog::new();
if config.quiet {
log.no_progress = true;
}
log.no_progress = match (config.quiet, config.progress.as_str()) {
(true, _) => true,
(_, "false") => true,
(_, "true") => false,
(_, _auto) => !stderr().is_terminal(),
};

let cwd = match std::env::current_dir() {
Ok(cwd) => cwd,
Expand Down

0 comments on commit 4305be2

Please sign in to comment.