Skip to content

Commit 56d347e

Browse files
committed
fix: remove the --output flag
1 parent 4a0ecc5 commit 56d347e

File tree

6 files changed

+8
-155
lines changed

6 files changed

+8
-155
lines changed

doc/fd.1

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -514,22 +514,6 @@ due to OS restrictions on the maximum length of command lines.
514514
.BI "\-\-json "
515515
Specify JSONL (as known as NDJSON) format to use for the output.
516516
.TP
517-
.BI "\-\-output "
518-
Specify a structured format to use for the output. The value can be plain (default), json, jsonl, or
519-
yaml.
520-
521-
Currently, the default is "plain", and if the option is used without an argument "plain"
522-
is used. The available options are:
523-
.RS
524-
.IP plain
525-
Output the results as plain text (default).
526-
.IP json
527-
Output the results as a JSON array.
528-
.IP jsonl
529-
Output the results as JSON Lines (as known as NDJSON).
530-
.IP yaml
531-
Output the results as YAML.
532-
.RE
533517
.SH PATTERN SYNTAX
534518
The regular expression syntax used by fd is documented here:
535519

src/cli.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -652,24 +652,11 @@ pub struct Opts {
652652
#[arg(
653653
long,
654654
value_name = "json",
655-
conflicts_with("output"),
656655
help = "Print results in JSONL format so you can pipe it to tools.",
657656
long_help
658657
)]
659658
pub json: bool,
660659

661-
/// Print results in a certain format so you can pipe it to tools.
662-
#[arg(
663-
long,
664-
value_name = "output",
665-
value_enum,
666-
default_value_t = OutputFormat::Plain,
667-
conflicts_with("format"),
668-
conflicts_with("list_details"),
669-
help = "Print results in a certain format so you can pipe it to tools."
670-
)]
671-
pub output: OutputFormat,
672-
673660
/// By default, relative paths are prefixed with './' when -x/--exec,
674661
/// -X/--exec-batch, or -0/--print0 are given, to reduce the risk of a
675662
/// path starting with '-' being treated as a command line option. Use
@@ -851,14 +838,9 @@ pub enum HyperlinkWhen {
851838
pub enum OutputFormat {
852839
/// Plain text output (default)
853840
Plain,
854-
/// JSON output
855-
Json,
856841
/// JSONL (JSON Lines, as known as Newline Delimited JSON) output
857842
#[value(alias = "ndjson")]
858843
Jsonl,
859-
/// YAML output
860-
#[value(alias = "yml")]
861-
Yaml,
862844
}
863845

864846
// there isn't a derive api for getting grouped values yet,

src/config.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::{path::PathBuf, sync::Arc, time::Duration};
33
use lscolors::LsColors;
44
use regex::bytes::RegexSet;
55

6-
use crate::cli::OutputFormat;
76
use crate::exec::CommandSet;
87
use crate::filetypes::FileTypes;
98
#[cfg(unix)]
@@ -134,9 +133,6 @@ pub struct Config {
134133

135134
/// Whether to print results in JSONL format
136135
pub jsonl: bool,
137-
138-
/// The output format to use
139-
pub output: OutputFormat,
140136
}
141137

142138
impl Config {

src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config
326326
actual_path_separator,
327327
max_results: opts.max_results(),
328328
strip_cwd_prefix: opts.strip_cwd_prefix(|| !(opts.null_separator || has_command)),
329-
output: opts.output,
330329
jsonl: opts.json,
331330
})
332331
}

src/output.rs

Lines changed: 7 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use lscolors::{Indicator, LsColors, Style};
99
use crate::cli::OutputFormat;
1010
use crate::config::Config;
1111
use crate::dir_entry::DirEntry;
12-
use crate::exit_codes::ExitCode;
1312
use crate::fmt::FormatTemplate;
1413
use crate::hyperlink::PathUrl;
1514

@@ -45,42 +44,11 @@ struct FileDetail<'a> {
4544
pub struct Printer<'a, W> {
4645
config: &'a Config,
4746
pub stdout: W,
48-
started: bool,
4947
}
5048

5149
impl<'a, W: Write> Printer<'a, W> {
5250
pub fn new(config: &'a Config, stdout: W) -> Self {
53-
Self {
54-
config,
55-
stdout,
56-
started: false,
57-
}
58-
}
59-
60-
/// Begin JSON array output if in JSON format.
61-
/// Returns an error if writing to output fails.
62-
pub fn begin(&mut self) -> Result<(), ExitCode> {
63-
if self.config.output == OutputFormat::Json
64-
&& let Err(e) = writeln!(self.stdout, "[")
65-
&& e.kind() != ::std::io::ErrorKind::BrokenPipe
66-
{
67-
crate::error::print_error(format!("Could not write to output: {e}"));
68-
return Err(ExitCode::GeneralError);
69-
}
70-
Ok(())
71-
}
72-
73-
/// End JSON array output if in JSON format.
74-
/// Returns an error if writing to output fails.
75-
pub fn end(&mut self) -> Result<(), ExitCode> {
76-
if self.config.output == OutputFormat::Json
77-
&& let Err(e) = writeln!(self.stdout, "\n]")
78-
&& e.kind() != ::std::io::ErrorKind::BrokenPipe
79-
{
80-
crate::error::print_error(format!("Could not write to output: {e}"));
81-
return Err(ExitCode::GeneralError);
82-
}
83-
Ok(())
51+
Self { config, stdout }
8452
}
8553

8654
// TODO: this function is performance critical and can probably be optimized
@@ -94,37 +62,19 @@ impl<'a, W: Write> Printer<'a, W> {
9462
}
9563
match (
9664
&self.config.format,
97-
&self.config.output,
9865
&self.config.jsonl,
9966
&self.config.ls_colors,
10067
) {
101-
(Some(template), _, _, _) => self.print_entry_format(entry, template)?,
102-
(None, _, true, _) => self.print_entry_detail(OutputFormat::Jsonl, entry)?,
103-
(None, OutputFormat::Json, false, _) => {
104-
self.print_entry_detail(OutputFormat::Json, entry)?
105-
}
106-
(None, OutputFormat::Yaml, false, _) => {
107-
self.print_entry_detail(OutputFormat::Yaml, entry)?
108-
}
109-
(None, OutputFormat::Jsonl, false, _) => {
110-
self.print_entry_detail(OutputFormat::Jsonl, entry)?
111-
}
112-
(None, OutputFormat::Plain, false, Some(ls_colors)) => {
113-
self.print_entry_colorized(entry, ls_colors)?
114-
}
115-
(None, OutputFormat::Plain, false, None) => self.print_entry_uncolorized(entry)?,
68+
(Some(template), _, _) => self.print_entry_format(entry, template)?,
69+
(None, true, _) => self.print_entry_detail(OutputFormat::Jsonl, entry)?,
70+
(None, false, Some(ls_colors)) => self.print_entry_colorized(entry, ls_colors)?,
71+
(None, false, None) => self.print_entry_uncolorized(entry)?,
11672
};
11773

11874
if has_hyperlink {
11975
write!(self.stdout, "\x1B]8;;\x1B\\")?;
12076
}
12177

122-
self.started = true;
123-
124-
if matches!(self.config.output, OutputFormat::Json) {
125-
return Ok(());
126-
}
127-
12878
if self.config.null_separator {
12979
write!(self.stdout, "\0")
13080
} else {
@@ -234,54 +184,7 @@ impl<'a, W: Write> Printer<'a, W> {
234184
}
235185
}
236186

237-
fn print_entry_yaml_obj(&mut self, detail: &FileDetail) -> io::Result<()> {
238-
// Manually construct a simple YAML representation
239-
// to avoid adding a dependency on serde_yaml (deprecated).
240-
//
241-
// Write YAML fragments directly to stdout (should be buffered)
242-
write!(self.stdout, "- ")?;
243-
244-
match &detail.path {
245-
PathEncoding::Utf8(path) => {
246-
writeln!(self.stdout, "path: \"{}\"", path)?;
247-
}
248-
PathEncoding::Bytes(bytes) => {
249-
writeln!(
250-
self.stdout,
251-
"path_base64: \"{}\"",
252-
BASE64_STANDARD.encode(bytes)
253-
)?;
254-
}
255-
}
256-
257-
writeln!(self.stdout, " type: {}", detail.file_type)?;
258-
259-
if let Some(size) = detail.size {
260-
writeln!(self.stdout, " size: {}", size)?;
261-
}
262-
if let Some(mode) = detail.mode {
263-
writeln!(self.stdout, " mode: 0o{mode:o}")?;
264-
}
265-
if let Some(modified) = &detail.modified {
266-
writeln!(self.stdout, " modified: \"{}\"", modified)?;
267-
}
268-
if let Some(accessed) = &detail.accessed {
269-
writeln!(self.stdout, " accessed: \"{}\"", accessed)?;
270-
}
271-
if let Some(created) = &detail.created {
272-
writeln!(self.stdout, " created: \"{}\"", created)?;
273-
}
274-
Ok(())
275-
}
276-
277-
fn print_entry_json_obj(&mut self, detail: &FileDetail, comma: bool) -> io::Result<()> {
278-
if self.started && comma {
279-
writeln!(self.stdout, ",")?;
280-
}
281-
282-
if comma {
283-
write!(self.stdout, " ")?;
284-
}
187+
fn print_entry_json_obj(&mut self, detail: &FileDetail) -> io::Result<()> {
285188
write!(self.stdout, "{{")?;
286189

287190
match &detail.path {
@@ -380,9 +283,7 @@ impl<'a, W: Write> Printer<'a, W> {
380283
}
381284
};
382285
match format {
383-
OutputFormat::Json => self.print_entry_json_obj(&detail, true),
384-
OutputFormat::Jsonl => self.print_entry_json_obj(&detail, false),
385-
OutputFormat::Yaml => self.print_entry_yaml_obj(&detail),
286+
OutputFormat::Jsonl => self.print_entry_json_obj(&detail),
386287
OutputFormat::Plain => unreachable!("Plain format should not call print_entry_detail"),
387288
}
388289
}

src/walk.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,12 @@ impl<'a, W: Write + 'static> ReceiverBuffer<'a, W> {
172172

173173
/// Process results until finished.
174174
fn process(&mut self) -> ExitCode {
175-
if let Err(err) = self.printer.begin() {
176-
return err;
177-
}
178-
let ec;
179175
loop {
180176
if let Err(err) = self.poll() {
181177
self.quit_flag.store(true, Ordering::Relaxed);
182-
ec = err;
183-
break;
178+
return err;
184179
}
185180
}
186-
if let Err(err) = self.printer.end() {
187-
return err;
188-
}
189-
ec
190181
}
191182

192183
/// Receive the next worker result.

0 commit comments

Comments
 (0)