|
@@ -10,7 +10,7 @@ use crate::output::table::{
|
|
|
Columns, FlagsFormat, GroupFormat, Options as TableOptions, SizeFormat, TimeTypes, UserFormat,
|
|
Columns, FlagsFormat, GroupFormat, Options as TableOptions, SizeFormat, TimeTypes, UserFormat,
|
|
|
};
|
|
};
|
|
|
use crate::output::time::TimeFormat;
|
|
use crate::output::time::TimeFormat;
|
|
|
-use crate::output::{details, grid, Mode, TerminalWidth, View};
|
|
|
|
|
|
|
+use crate::output::{details, grid, Mode, OutputType, TerminalWidth, View};
|
|
|
|
|
|
|
|
impl View {
|
|
impl View {
|
|
|
pub fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
|
|
pub fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
|
|
@@ -19,16 +19,28 @@ impl View {
|
|
|
let total_size = matches.has(&flags::TOTAL_SIZE)?;
|
|
let total_size = matches.has(&flags::TOTAL_SIZE)?;
|
|
|
let width = TerminalWidth::deduce(matches, vars)?;
|
|
let width = TerminalWidth::deduce(matches, vars)?;
|
|
|
let file_style = FileStyle::deduce(matches, vars, width.actual_terminal_width().is_some())?;
|
|
let file_style = FileStyle::deduce(matches, vars, width.actual_terminal_width().is_some())?;
|
|
|
|
|
+ let output_type = OutputType::deduce(matches)?;
|
|
|
Ok(Self {
|
|
Ok(Self {
|
|
|
mode,
|
|
mode,
|
|
|
width,
|
|
width,
|
|
|
file_style,
|
|
file_style,
|
|
|
deref_links,
|
|
deref_links,
|
|
|
total_size,
|
|
total_size,
|
|
|
|
|
+ output_type,
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+impl OutputType {
|
|
|
|
|
+ fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
|
|
|
|
|
+ if matches.has(&flags::JSON)? {
|
|
|
|
|
+ Ok(Self::Json)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Ok(Self::Legacy)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
impl Mode {
|
|
impl Mode {
|
|
|
/// Determine which viewing mode to use based on the user’s options.
|
|
/// Determine which viewing mode to use based on the user’s options.
|
|
|
///
|
|
///
|
|
@@ -44,7 +56,6 @@ impl Mode {
|
|
|
|| f.matches(&flags::ONE_LINE)
|
|
|| f.matches(&flags::ONE_LINE)
|
|
|
|| f.matches(&flags::GRID)
|
|
|| f.matches(&flags::GRID)
|
|
|
|| f.matches(&flags::TREE)
|
|
|| f.matches(&flags::TREE)
|
|
|
- || f.matches(&flags::JSON)
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
let Some(flag) = flag else {
|
|
let Some(flag) = flag else {
|
|
@@ -90,17 +101,6 @@ impl Mode {
|
|
|
return Ok(Self::Lines);
|
|
return Ok(Self::Lines);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if flag.matches(&flags::JSON) && !flag.matches(&flags::ONE_LINE) {
|
|
|
|
|
- let _ = matches.has(&flags::JSON)?;
|
|
|
|
|
- let details = details::Options::deduce_long(matches, vars)?;
|
|
|
|
|
- return Ok(Self::Json(Some(details)));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if flag.matches(&flags::JSON) && flag.matches(&flags::ONE_LINE) {
|
|
|
|
|
- let _ = matches.has(&flags::JSON)?;
|
|
|
|
|
- return Ok(Self::Json(None));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
let grid = grid::Options::deduce(matches)?;
|
|
let grid = grid::Options::deduce(matches)?;
|
|
|
Ok(Self::Grid(grid))
|
|
Ok(Self::Grid(grid))
|
|
|
}
|
|
}
|