view.rs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. use output::{View, Mode, grid, details, lines};
  2. use output::grid_details::{self, RowThreshold};
  3. use output::table::{TimeTypes, Environment, SizeFormat, Columns, Options as TableOptions};
  4. use output::time::TimeFormat;
  5. use options::{flags, Misfire, Vars};
  6. use options::parser::MatchedFlags;
  7. use fs::feature::xattr;
  8. impl View {
  9. /// Determine which view to use and all of that view’s arguments.
  10. pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<View, Misfire> {
  11. use options::style::Styles;
  12. let mode = Mode::deduce(matches, vars)?;
  13. let Styles { colours, style } = Styles::deduce(matches, vars, || *TERM_WIDTH)?;
  14. Ok(View { mode, colours, style })
  15. }
  16. }
  17. impl Mode {
  18. /// Determine the mode from the command-line arguments.
  19. pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Mode, Misfire> {
  20. use options::misfire::Misfire::*;
  21. let long = || {
  22. if matches.has(&flags::ACROSS)? && !matches.has(&flags::GRID)? {
  23. Err(Useless(&flags::ACROSS, true, &flags::LONG))
  24. }
  25. else if matches.has(&flags::ONE_LINE)? {
  26. Err(Useless(&flags::ONE_LINE, true, &flags::LONG))
  27. }
  28. else {
  29. Ok(details::Options {
  30. table: Some(TableOptions::deduce(matches)?),
  31. header: matches.has(&flags::HEADER)?,
  32. xattr: xattr::ENABLED && matches.has(&flags::EXTENDED)?,
  33. icons: matches.has(&flags::ICONS)?,
  34. })
  35. }
  36. };
  37. let other_options_scan = || {
  38. if let Some(width) = TerminalWidth::deduce(vars)?.width() {
  39. if matches.has(&flags::ONE_LINE)? {
  40. if matches.has(&flags::ACROSS)? {
  41. Err(Useless(&flags::ACROSS, true, &flags::ONE_LINE))
  42. }
  43. else {
  44. let lines = lines::Options { icons: matches.has(&flags::ICONS)? };
  45. Ok(Mode::Lines(lines))
  46. }
  47. }
  48. else if matches.has(&flags::TREE)? {
  49. let details = details::Options {
  50. table: None,
  51. header: false,
  52. xattr: xattr::ENABLED && matches.has(&flags::EXTENDED)?,
  53. icons: matches.has(&flags::ICONS)?,
  54. };
  55. Ok(Mode::Details(details))
  56. }
  57. else {
  58. let grid = grid::Options {
  59. across: matches.has(&flags::ACROSS)?,
  60. console_width: width,
  61. icons: matches.has(&flags::ICONS)?,
  62. };
  63. Ok(Mode::Grid(grid))
  64. }
  65. }
  66. else {
  67. // If the terminal width couldn’t be matched for some reason, such
  68. // as the program’s stdout being connected to a file, then
  69. // fallback to the lines view.
  70. if matches.has(&flags::TREE)? {
  71. let details = details::Options {
  72. table: None,
  73. header: false,
  74. xattr: xattr::ENABLED && matches.has(&flags::EXTENDED)?,
  75. icons: matches.has(&flags::ICONS)?,
  76. };
  77. Ok(Mode::Details(details))
  78. }
  79. else {
  80. let lines = lines::Options { icons: matches.has(&flags::ICONS)?, };
  81. Ok(Mode::Lines(lines))
  82. }
  83. }
  84. };
  85. if matches.has(&flags::LONG)? {
  86. let details = long()?;
  87. if matches.has(&flags::GRID)? {
  88. let other_options_mode = other_options_scan()?;
  89. if let Mode::Grid(grid) = other_options_mode {
  90. let row_threshold = RowThreshold::deduce(vars)?;
  91. return Ok(Mode::GridDetails(grid_details::Options { grid, details, row_threshold }));
  92. }
  93. else {
  94. return Ok(other_options_mode);
  95. }
  96. }
  97. else {
  98. return Ok(Mode::Details(details));
  99. }
  100. }
  101. // If --long hasn’t been passed, then check if we need to warn the
  102. // user about flags that won’t have any effect.
  103. if matches.is_strict() {
  104. for option in &[ &flags::BINARY, &flags::BYTES, &flags::INODE, &flags::LINKS,
  105. &flags::HEADER, &flags::BLOCKS, &flags::TIME, &flags::GROUP ] {
  106. if matches.has(option)? {
  107. return Err(Useless(*option, false, &flags::LONG));
  108. }
  109. }
  110. if cfg!(feature="git") && matches.has(&flags::GIT)? {
  111. return Err(Useless(&flags::GIT, false, &flags::LONG));
  112. }
  113. else if matches.has(&flags::LEVEL)? && !matches.has(&flags::RECURSE)? && !matches.has(&flags::TREE)? {
  114. // TODO: I'm not sure if the code even gets this far.
  115. // There is an identical check in dir_action
  116. return Err(Useless2(&flags::LEVEL, &flags::RECURSE, &flags::TREE));
  117. }
  118. }
  119. other_options_scan()
  120. }
  121. }
  122. /// The width of the terminal requested by the user.
  123. #[derive(PartialEq, Debug)]
  124. enum TerminalWidth {
  125. /// The user requested this specific number of columns.
  126. Set(usize),
  127. /// The terminal was found to have this number of columns.
  128. Terminal(usize),
  129. /// The user didn’t request any particular terminal width.
  130. Unset,
  131. }
  132. impl TerminalWidth {
  133. /// Determine a requested terminal width from the command-line arguments.
  134. ///
  135. /// Returns an error if a requested width doesn’t parse to an integer.
  136. fn deduce<V: Vars>(vars: &V) -> Result<TerminalWidth, Misfire> {
  137. use options::vars;
  138. if let Some(columns) = vars.get(vars::COLUMNS).and_then(|s| s.into_string().ok()) {
  139. match columns.parse() {
  140. Ok(width) => Ok(TerminalWidth::Set(width)),
  141. Err(e) => Err(Misfire::FailedParse(e)),
  142. }
  143. }
  144. else if let Some(width) = *TERM_WIDTH {
  145. Ok(TerminalWidth::Terminal(width))
  146. }
  147. else {
  148. Ok(TerminalWidth::Unset)
  149. }
  150. }
  151. fn width(&self) -> Option<usize> {
  152. match *self {
  153. TerminalWidth::Set(width) |
  154. TerminalWidth::Terminal(width) => Some(width),
  155. TerminalWidth::Unset => None,
  156. }
  157. }
  158. }
  159. impl RowThreshold {
  160. /// Determine whether to use a row threshold based on the given
  161. /// environment variables.
  162. fn deduce<V: Vars>(vars: &V) -> Result<RowThreshold, Misfire> {
  163. use options::vars;
  164. if let Some(columns) = vars.get(vars::EXA_GRID_ROWS).and_then(|s| s.into_string().ok()) {
  165. match columns.parse() {
  166. Ok(rows) => Ok(RowThreshold::MinimumRows(rows)),
  167. Err(e) => Err(Misfire::FailedParse(e)),
  168. }
  169. }
  170. else {
  171. Ok(RowThreshold::AlwaysGrid)
  172. }
  173. }
  174. }
  175. impl TableOptions {
  176. fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> {
  177. let env = Environment::load_all();
  178. let time_format = TimeFormat::deduce(matches)?;
  179. let size_format = SizeFormat::deduce(matches)?;
  180. let extra_columns = Columns::deduce(matches)?;
  181. Ok(TableOptions { env, time_format, size_format, extra_columns })
  182. }
  183. }
  184. impl Columns {
  185. fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> {
  186. let time_types = TimeTypes::deduce(matches)?;
  187. let git = cfg!(feature="git") && matches.has(&flags::GIT)?;
  188. let blocks = matches.has(&flags::BLOCKS)?;
  189. let group = matches.has(&flags::GROUP)?;
  190. let inode = matches.has(&flags::INODE)?;
  191. let links = matches.has(&flags::LINKS)?;
  192. Ok(Columns { time_types, git, blocks, group, inode, links })
  193. }
  194. }
  195. impl SizeFormat {
  196. /// Determine which file size to use in the file size column based on
  197. /// the user’s options.
  198. ///
  199. /// The default mode is to use the decimal prefixes, as they are the
  200. /// most commonly-understood, and don’t involve trying to parse large
  201. /// strings of digits in your head. Changing the format to anything else
  202. /// involves the `--binary` or `--bytes` flags, and these conflict with
  203. /// each other.
  204. fn deduce(matches: &MatchedFlags) -> Result<SizeFormat, Misfire> {
  205. let flag = matches.has_where(|f| f.matches(&flags::BINARY) || f.matches(&flags::BYTES))?;
  206. Ok(match flag {
  207. Some(f) if f.matches(&flags::BINARY) => SizeFormat::BinaryBytes,
  208. Some(f) if f.matches(&flags::BYTES) => SizeFormat::JustBytes,
  209. _ => SizeFormat::DecimalBytes,
  210. })
  211. }
  212. }
  213. impl TimeFormat {
  214. /// Determine how time should be formatted in timestamp columns.
  215. fn deduce(matches: &MatchedFlags) -> Result<TimeFormat, Misfire> {
  216. pub use output::time::{DefaultFormat, ISOFormat};
  217. let word = match matches.get(&flags::TIME_STYLE)? {
  218. Some(w) => w,
  219. None => return Ok(TimeFormat::DefaultFormat(DefaultFormat::new())),
  220. };
  221. if word == "default" {
  222. Ok(TimeFormat::DefaultFormat(DefaultFormat::new()))
  223. }
  224. else if word == "iso" {
  225. Ok(TimeFormat::ISOFormat(ISOFormat::new()))
  226. }
  227. else if word == "long-iso" {
  228. Ok(TimeFormat::LongISO)
  229. }
  230. else if word == "full-iso" {
  231. Ok(TimeFormat::FullISO)
  232. }
  233. else {
  234. Err(Misfire::BadArgument(&flags::TIME_STYLE, word.into()))
  235. }
  236. }
  237. }
  238. impl TimeTypes {
  239. /// Determine which of a file’s time fields should be displayed for it
  240. /// based on the user’s options.
  241. ///
  242. /// There are two separate ways to pick which fields to show: with a
  243. /// flag (such as `--modified`) or with a parameter (such as
  244. /// `--time=modified`). An error is signaled if both ways are used.
  245. ///
  246. /// It’s valid to show more than one column by passing in more than one
  247. /// option, but passing *no* options means that the user just wants to
  248. /// see the default set.
  249. fn deduce(matches: &MatchedFlags) -> Result<TimeTypes, Misfire> {
  250. let possible_word = matches.get(&flags::TIME)?;
  251. let modified = matches.has(&flags::MODIFIED)?;
  252. let created = matches.has(&flags::CREATED)?;
  253. let accessed = matches.has(&flags::ACCESSED)?;
  254. if let Some(word) = possible_word {
  255. if modified {
  256. Err(Misfire::Useless(&flags::MODIFIED, true, &flags::TIME))
  257. }
  258. else if created {
  259. Err(Misfire::Useless(&flags::CREATED, true, &flags::TIME))
  260. }
  261. else if accessed {
  262. Err(Misfire::Useless(&flags::ACCESSED, true, &flags::TIME))
  263. }
  264. else if word == "mod" || word == "modified" {
  265. Ok(TimeTypes { accessed: false, modified: true, created: false })
  266. }
  267. else if word == "acc" || word == "accessed" {
  268. Ok(TimeTypes { accessed: true, modified: false, created: false })
  269. }
  270. else if word == "cr" || word == "created" {
  271. Ok(TimeTypes { accessed: false, modified: false, created: true })
  272. }
  273. else {
  274. Err(Misfire::BadArgument(&flags::TIME, word.into()))
  275. }
  276. }
  277. else if modified || created || accessed {
  278. Ok(TimeTypes { accessed, modified, created })
  279. }
  280. else {
  281. Ok(TimeTypes::default())
  282. }
  283. }
  284. }
  285. // Gets, then caches, the width of the terminal that exa is running in.
  286. // This gets used multiple times above, with no real guarantee of order,
  287. // so it’s easier to just cache it the first time it runs.
  288. lazy_static! {
  289. static ref TERM_WIDTH: Option<usize> = {
  290. // All of stdin, stdout, and stderr could not be connected to a
  291. // terminal, but we’re only interested in stdout because it’s
  292. // where the output goes.
  293. use term_size::dimensions_stdout;
  294. dimensions_stdout().map(|t| t.0)
  295. };
  296. }
  297. #[cfg(test)]
  298. mod test {
  299. use super::*;
  300. use std::ffi::OsString;
  301. use options::flags;
  302. use options::parser::{Flag, Arg};
  303. use options::test::parse_for_test;
  304. use options::test::Strictnesses::*;
  305. static TEST_ARGS: &[&Arg] = &[ &flags::BINARY, &flags::BYTES, &flags::TIME_STYLE,
  306. &flags::TIME, &flags::MODIFIED, &flags::CREATED, &flags::ACCESSED,
  307. &flags::HEADER, &flags::GROUP, &flags::ICONS, &flags::INODE,
  308. &flags::GIT, &flags::LINKS, &flags::BLOCKS, &flags::LONG,
  309. &flags::LEVEL, &flags::GRID, &flags::ACROSS, &flags::ONE_LINE ];
  310. macro_rules! test {
  311. ($name:ident: $type:ident <- $inputs:expr; $stricts:expr => $result:expr) => {
  312. /// Macro that writes a test.
  313. /// If testing both strictnesses, they’ll both be done in the same function.
  314. #[test]
  315. fn $name() {
  316. for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) {
  317. assert_eq!(result, $result);
  318. }
  319. }
  320. };
  321. ($name:ident: $type:ident <- $inputs:expr; $stricts:expr => err $result:expr) => {
  322. /// Special macro for testing Err results.
  323. /// This is needed because sometimes the Ok type doesn’t implement PartialEq.
  324. #[test]
  325. fn $name() {
  326. for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) {
  327. assert_eq!(result.unwrap_err(), $result);
  328. }
  329. }
  330. };
  331. ($name:ident: $type:ident <- $inputs:expr; $stricts:expr => like $pat:pat) => {
  332. /// More general macro for testing against a pattern.
  333. /// Instead of using PartialEq, this just tests if it matches a pat.
  334. #[test]
  335. fn $name() {
  336. for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) {
  337. println!("Testing {:?}", result);
  338. match result {
  339. $pat => assert!(true),
  340. _ => assert!(false),
  341. }
  342. }
  343. }
  344. };
  345. ($name:ident: $type:ident <- $inputs:expr, $vars:expr; $stricts:expr => err $result:expr) => {
  346. /// Like above, but with $vars.
  347. #[test]
  348. fn $name() {
  349. for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf, &$vars)) {
  350. assert_eq!(result.unwrap_err(), $result);
  351. }
  352. }
  353. };
  354. ($name:ident: $type:ident <- $inputs:expr, $vars:expr; $stricts:expr => like $pat:pat) => {
  355. /// Like further above, but with $vars.
  356. #[test]
  357. fn $name() {
  358. for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf, &$vars)) {
  359. println!("Testing {:?}", result);
  360. match result {
  361. $pat => assert!(true),
  362. _ => assert!(false),
  363. }
  364. }
  365. }
  366. };
  367. }
  368. mod size_formats {
  369. use super::*;
  370. // Default behaviour
  371. test!(empty: SizeFormat <- []; Both => Ok(SizeFormat::DecimalBytes));
  372. // Individual flags
  373. test!(binary: SizeFormat <- ["--binary"]; Both => Ok(SizeFormat::BinaryBytes));
  374. test!(bytes: SizeFormat <- ["--bytes"]; Both => Ok(SizeFormat::JustBytes));
  375. // Overriding
  376. test!(both_1: SizeFormat <- ["--binary", "--binary"]; Last => Ok(SizeFormat::BinaryBytes));
  377. test!(both_2: SizeFormat <- ["--bytes", "--binary"]; Last => Ok(SizeFormat::BinaryBytes));
  378. test!(both_3: SizeFormat <- ["--binary", "--bytes"]; Last => Ok(SizeFormat::JustBytes));
  379. test!(both_4: SizeFormat <- ["--bytes", "--bytes"]; Last => Ok(SizeFormat::JustBytes));
  380. test!(both_5: SizeFormat <- ["--binary", "--binary"]; Complain => err Misfire::Duplicate(Flag::Long("binary"), Flag::Long("binary")));
  381. test!(both_6: SizeFormat <- ["--bytes", "--binary"]; Complain => err Misfire::Duplicate(Flag::Long("bytes"), Flag::Long("binary")));
  382. test!(both_7: SizeFormat <- ["--binary", "--bytes"]; Complain => err Misfire::Duplicate(Flag::Long("binary"), Flag::Long("bytes")));
  383. test!(both_8: SizeFormat <- ["--bytes", "--bytes"]; Complain => err Misfire::Duplicate(Flag::Long("bytes"), Flag::Long("bytes")));
  384. }
  385. mod time_formats {
  386. use super::*;
  387. // These tests use pattern matching because TimeFormat doesn’t
  388. // implement PartialEq.
  389. // Default behaviour
  390. test!(empty: TimeFormat <- []; Both => like Ok(TimeFormat::DefaultFormat(_)));
  391. // Individual settings
  392. test!(default: TimeFormat <- ["--time-style=default"]; Both => like Ok(TimeFormat::DefaultFormat(_)));
  393. test!(iso: TimeFormat <- ["--time-style", "iso"]; Both => like Ok(TimeFormat::ISOFormat(_)));
  394. test!(long_iso: TimeFormat <- ["--time-style=long-iso"]; Both => like Ok(TimeFormat::LongISO));
  395. test!(full_iso: TimeFormat <- ["--time-style", "full-iso"]; Both => like Ok(TimeFormat::FullISO));
  396. // Overriding
  397. test!(actually: TimeFormat <- ["--time-style=default", "--time-style", "iso"]; Last => like Ok(TimeFormat::ISOFormat(_)));
  398. test!(actual_2: TimeFormat <- ["--time-style=default", "--time-style", "iso"]; Complain => err Misfire::Duplicate(Flag::Long("time-style"), Flag::Long("time-style")));
  399. test!(nevermind: TimeFormat <- ["--time-style", "long-iso", "--time-style=full-iso"]; Last => like Ok(TimeFormat::FullISO));
  400. test!(nevermore: TimeFormat <- ["--time-style", "long-iso", "--time-style=full-iso"]; Complain => err Misfire::Duplicate(Flag::Long("time-style"), Flag::Long("time-style")));
  401. // Errors
  402. test!(daily: TimeFormat <- ["--time-style=24-hour"]; Both => err Misfire::BadArgument(&flags::TIME_STYLE, OsString::from("24-hour")));
  403. }
  404. mod time_types {
  405. use super::*;
  406. // Default behaviour
  407. test!(empty: TimeTypes <- []; Both => Ok(TimeTypes::default()));
  408. // Modified
  409. test!(modified: TimeTypes <- ["--modified"]; Both => Ok(TimeTypes { accessed: false, modified: true, created: false }));
  410. test!(m: TimeTypes <- ["-m"]; Both => Ok(TimeTypes { accessed: false, modified: true, created: false }));
  411. test!(time_mod: TimeTypes <- ["--time=modified"]; Both => Ok(TimeTypes { accessed: false, modified: true, created: false }));
  412. test!(time_m: TimeTypes <- ["-tmod"]; Both => Ok(TimeTypes { accessed: false, modified: true, created: false }));
  413. // Accessed
  414. test!(acc: TimeTypes <- ["--accessed"]; Both => Ok(TimeTypes { accessed: true, modified: false, created: false }));
  415. test!(a: TimeTypes <- ["-u"]; Both => Ok(TimeTypes { accessed: true, modified: false, created: false }));
  416. test!(time_acc: TimeTypes <- ["--time", "accessed"]; Both => Ok(TimeTypes { accessed: true, modified: false, created: false }));
  417. test!(time_a: TimeTypes <- ["-t", "acc"]; Both => Ok(TimeTypes { accessed: true, modified: false, created: false }));
  418. // Created
  419. test!(cr: TimeTypes <- ["--created"]; Both => Ok(TimeTypes { accessed: false, modified: false, created: true }));
  420. test!(c: TimeTypes <- ["-U"]; Both => Ok(TimeTypes { accessed: false, modified: false, created: true }));
  421. test!(time_cr: TimeTypes <- ["--time=created"]; Both => Ok(TimeTypes { accessed: false, modified: false, created: true }));
  422. test!(time_c: TimeTypes <- ["-tcr"]; Both => Ok(TimeTypes { accessed: false, modified: false, created: true }));
  423. // Multiples
  424. test!(time_uu: TimeTypes <- ["-uU"]; Both => Ok(TimeTypes { accessed: true, modified: false, created: true }));
  425. // Errors
  426. test!(time_tea: TimeTypes <- ["--time=tea"]; Both => err Misfire::BadArgument(&flags::TIME, OsString::from("tea")));
  427. test!(time_ea: TimeTypes <- ["-tea"]; Both => err Misfire::BadArgument(&flags::TIME, OsString::from("ea")));
  428. // Overriding
  429. test!(overridden: TimeTypes <- ["-tcr", "-tmod"]; Last => Ok(TimeTypes { accessed: false, modified: true, created: false }));
  430. test!(overridden_2: TimeTypes <- ["-tcr", "-tmod"]; Complain => err Misfire::Duplicate(Flag::Short(b't'), Flag::Short(b't')));
  431. }
  432. mod views {
  433. use super::*;
  434. use output::grid::Options as GridOptions;
  435. use output::lines::Options as LineOptions;
  436. // Default
  437. test!(empty: Mode <- [], None; Both => like Ok(Mode::Grid(_)));
  438. // Grid views
  439. test!(original_g: Mode <- ["-G"], None; Both => like Ok(Mode::Grid(GridOptions { across: false, console_width: _, icons: _ })));
  440. test!(grid: Mode <- ["--grid"], None; Both => like Ok(Mode::Grid(GridOptions { across: false, console_width: _, icons: _ })));
  441. test!(across: Mode <- ["--across"], None; Both => like Ok(Mode::Grid(GridOptions { across: true, console_width: _, icons: _ })));
  442. test!(gracross: Mode <- ["-xG"], None; Both => like Ok(Mode::Grid(GridOptions { across: true, console_width: _, icons: _ })));
  443. test!(icons: Mode <- ["--icons"], None; Both => like Ok(Mode::Grid(GridOptions { across: _, console_width: _, icons: true})));
  444. // Lines views
  445. test!(lines: Mode <- ["--oneline"], None; Both => like Ok(Mode::Lines(LineOptions{ icons: _ })));
  446. test!(prima: Mode <- ["-1"], None; Both => like Ok(Mode::Lines(LineOptions{ icons: _ })));
  447. test!(line_icon: Mode <- ["-1", "--icons"], None; Both => like Ok(Mode::Lines(LineOptions { icons: true })));
  448. // Details views
  449. test!(long: Mode <- ["--long"], None; Both => like Ok(Mode::Details(_)));
  450. test!(ell: Mode <- ["-l"], None; Both => like Ok(Mode::Details(_)));
  451. // Grid-details views
  452. test!(lid: Mode <- ["--long", "--grid"], None; Both => like Ok(Mode::GridDetails(_)));
  453. test!(leg: Mode <- ["-lG"], None; Both => like Ok(Mode::GridDetails(_)));
  454. // Options that do nothing without --long
  455. test!(just_header: Mode <- ["--header"], None; Last => like Ok(Mode::Grid(_)));
  456. test!(just_group: Mode <- ["--group"], None; Last => like Ok(Mode::Grid(_)));
  457. test!(just_inode: Mode <- ["--inode"], None; Last => like Ok(Mode::Grid(_)));
  458. test!(just_links: Mode <- ["--links"], None; Last => like Ok(Mode::Grid(_)));
  459. test!(just_blocks: Mode <- ["--blocks"], None; Last => like Ok(Mode::Grid(_)));
  460. test!(just_binary: Mode <- ["--binary"], None; Last => like Ok(Mode::Grid(_)));
  461. test!(just_bytes: Mode <- ["--bytes"], None; Last => like Ok(Mode::Grid(_)));
  462. #[cfg(feature="git")]
  463. test!(just_git: Mode <- ["--git"], None; Last => like Ok(Mode::Grid(_)));
  464. test!(just_header_2: Mode <- ["--header"], None; Complain => err Misfire::Useless(&flags::HEADER, false, &flags::LONG));
  465. test!(just_group_2: Mode <- ["--group"], None; Complain => err Misfire::Useless(&flags::GROUP, false, &flags::LONG));
  466. test!(just_inode_2: Mode <- ["--inode"], None; Complain => err Misfire::Useless(&flags::INODE, false, &flags::LONG));
  467. test!(just_links_2: Mode <- ["--links"], None; Complain => err Misfire::Useless(&flags::LINKS, false, &flags::LONG));
  468. test!(just_blocks_2: Mode <- ["--blocks"], None; Complain => err Misfire::Useless(&flags::BLOCKS, false, &flags::LONG));
  469. test!(just_binary_2: Mode <- ["--binary"], None; Complain => err Misfire::Useless(&flags::BINARY, false, &flags::LONG));
  470. test!(just_bytes_2: Mode <- ["--bytes"], None; Complain => err Misfire::Useless(&flags::BYTES, false, &flags::LONG));
  471. #[cfg(feature="git")]
  472. test!(just_git_2: Mode <- ["--git"], None; Complain => err Misfire::Useless(&flags::GIT, false, &flags::LONG));
  473. }
  474. }