Commit Graph

921 Commits

Author SHA1 Message Date
Benjamin Sago
6740faa781 env vars should be referenced, not copied
Just because the type that gets used right now is Copy and Clone doesn’t mean that when we pass mock ones in for tests they’ll be those two as well. So we have to go through and add &s everywhere.
2017-08-13 11:14:58 +01:00
Benjamin Sago
33e83accd0 match-to-if-let 2017-08-12 22:51:45 +01:00
Benjamin Sago
da00e2fda2 Thread the row threshold through grid_details
No new features here, just some restructuring. Mode::GridDetails was nice and elegant with those two fields, but now there’s a grid-details-only option the elegance has gone out the window.
2017-08-12 22:49:16 +01:00
Benjamin Sago
a6ed42105d By lines, I meant details
Yeah, I forgot what I was meant to be doing half-way through.

This also adds the row_threshold field, which disables the view unless there will be more than the given number of rows. Getting the row count required upgrading term_grid to a version that has that function added.
2017-08-12 20:19:30 +01:00
Benjamin Sago
513ec51358 Have grid-details turn into lines if it won’t fit
Previously the iterator went all the way through `2..`, and not only would that take a very long time, but at the end it wouldn’t even print anything. Now the grid-details view turns into a lines view when it’s hit its limit.
2017-08-12 14:21:34 +01:00
Benjamin Sago
6343fbc040 Remove unnecessary clone (plus docs) 2017-08-12 12:50:59 +01:00
Benjamin Sago
e45e515805 Remove stray colon from help text
Fixes #266
2017-08-12 11:39:12 +01:00
Benjamin Sago
e29f06fae0 Merge pull request #258 from chrisvittal/compression-types
Add extra types to compressed filetype filter.
2017-08-12 11:32:31 +01:00
Benjamin Sago
9e15c616cc dir_action comments and docs 2017-08-12 11:29:40 +01:00
Benjamin Sago
673e894d25 Give the filter modules some love 2017-08-12 10:09:33 +01:00
Benjamin Sago
a7d8e1c84b Make the dir action a bit more lenient
More strict mode checks I forgot to take out
2017-08-11 22:56:52 +01:00
Benjamin Sago
eec1a4f78a Stop --git from complaining too
Re-fixes #152
2017-08-11 21:43:56 +01:00
Benjamin Sago
5189d66e2c Hide xattr errors unless --extended
exa now ignores errors when checking for extended attributes when the user didn’t explicitly demand that they be checked. If a file does have xattrs, it’ll still display the @ in the permissions column; errors will now just cause the @ to be hidden instead.

This changed a lot of the xtests, which were displaying the error message in a few situations. Those tests have gained @-suffixed companions so the actual error messages can still be tested.

Fixes #178 (finally)
2017-08-11 12:36:14 +01:00
Benjamin Sago
97d1472331 Merge branch 'strict-mode-properly'
This adds a check for the EXA_STRICT environment variable, and uses it to put exa in a strict mode, which enables more checks for useless/redundant arguments.

Its other goal was to move all the option parsing tests out of options/mod.rs and into the files where they’re actually relevant. THIS IS NOT YET DONE and I’ll have to do some more work on this prior to release to clear up the last few lingering issues. There are almost certainly going to be cases where redundant arguments are still complained about (or ignored) by mistake.

But I want to get this branch merged so I can take care of some other stuff for the next release.
2017-08-11 10:08:25 +01:00
Benjamin Sago
b286676667 Add actual error messages for the error messages
The annoying part is trying to format!() an OsStr.
2017-08-10 23:34:39 +01:00
Benjamin Sago
adaa36e1c5 Integrate strict mode, use it to test file sizes
It’s a good test to be able to switch strict mode on in run.sh and not have it break anything! Now, the EXA_STRICT environment variable will toggle it on. We can even switch it off and see that it doesn’t error.
2017-08-10 18:45:26 +01:00
Benjamin Sago
dbebd60c4e Extract var_os and use the mock to test
Some of the deduce functions used to just blatantly call std::env::var_os and not care, introducing global state into a module that was otherwise nice and functional and self-contained. (Well, almost. There’s still terminal width.)

Anyway, this made it hard to test, because we couldn’t test it fully with this global dependency in place. It *is* possible to work around this by actually setting the environment variables in the tests, but this way is more self-documenting.

With this in place, we can start to unit test things like deriving the view by passing in what the $COLUMNS environment variable should be, and that’s one of the first things checked.

src/options/mod.rs *almost* has all its tests moved to where they should be!
2017-08-10 17:54:28 +01:00
Benjamin Sago
532ebbc591 Only complain about long options in strict mode
Fixes #152. It just puts the check behind a flag and moves the tests around.
2017-08-10 13:59:39 +01:00
Benjamin Sago
f389943bf1 New macro for testing deduce errors
Sometimes, the type in the Ok part of the Result wouldn’t implement PartialEq, so the first macro (which uses assert_eq) won’t work. In these cases, this new macro can be used instead, which just unwraps the Err’s contents. In other cases, it can shave off a ) at the end of a few lines.
2017-08-10 13:59:09 +01:00
Benjamin Sago
6755ee6ae9 Extract table columns into a struct
The table Options struct is roughly half runtime configuration and half flags to select which columns to display The column fields might as well be in their own struct, and now that the ‘for_dir’ function doesn’t use SizeFormat, it can be moved to Columns.
2017-08-09 22:25:16 +01:00
Benjamin Sago
e98c765078 Move size format out of Column
Way in the past, the size format was the only variable column; the others were all fixed. Now there are many configurable columns and this field was still hanging around. The code that does the rendering just gets the size format as an argument, and now it works the same way as the TimeFormat.
2017-08-09 21:47:51 +01:00
Benjamin Sago
6b309d5cfc Make SizeFormat lenient, and add tests
This changes the SizeFormat option parser from its old, strict-by-default behaviour (where passing both --bytes and --binary would be an error) to the new, use-the-last-argument behaviour (where passing --bytes --binary would use --binary because it came later).

Doing this meant adding functionality to Matches so that it could return *which* argument matched. Previously, the order of --bytes and --binary didn’t matter, because they couldn’t both be present, but now it does.
2017-08-09 19:18:31 +01:00
Benjamin Sago
b2947ed590 Document and test time formats 2017-08-09 17:14:16 +01:00
Benjamin Sago
0b87392fd4 Decouple assert_eq! and assert_parses
The assert_parses function was problematic because it insisted on using assert_eq! to check its contents. This won’t work for any type we want to test that doesn’t implement PartialEq, such as TimeFormat, which holds references to years and date strings and other such.

To go about fixing this, the first step is to change that function so it only does the initial processing, rather than the assertion, which is now done outside of it in the test macros instead.
2017-08-09 13:41:07 +01:00
Benjamin Sago
ff497b52e5 Be stricter in strict mode
Now the code actually starts to use the Strictness flag that was added in the earlier commit! Well, the *code* doesn’t, but the tests do: the macros that create the test cases now have a parameter for which tests they should run. It’s usually ‘Both’ for both strict mode and default mode, but can be specified to only run in one, for when the results differ (usually when options override one another)

The downside to strict mode is that, now, *any* call to `matches.has` or `matches.get` could fail, because an option could have been specified twice, and this is the place where those are checked for. This makes the code a little less ergonomic in places, but that’s what the ? operator is for. The only place this has really had an effect is in `Classify::deduce`, which used to just return a boolean but can now fail.

In order to more thoroughly test the mode, some of the older parts of the code can now act more strict. For example, `TerminalColours::deduce` will now use the last-given option rather than searching for “colours” before “colors”.

Help and Version continue doing their own thing.
2017-08-09 09:21:29 +01:00
Benjamin Sago
d97f603ee3 Make these tests less long 2017-08-08 09:20:46 +01:00
Benjamin Sago
00379cce63 Thread Strictness through the parser
The value is ignored, but this broke quite a lot of tests that assumed MatchedFlags had only one field.

Parsing tests have to have OsStr flags because I couldn’t get that part working right, but in general, some tests now re-use common functionality too.
2017-08-08 09:18:17 +01:00
Benjamin Sago
c1e206669e Give IgnorePatterns a better interface
This commit gives IgnorePatterns a bunch of constructor methods that mean its option-parsing sister file doesn’t need to know that it’s a vec of glob patterns inside: it can work with anything that iterates over strings. Now, the options module doesn’t need to know about the glob crate.
2017-08-07 09:16:56 +01:00
Christopher Vittal
1bce51c9c8 Add extra types to compressed filetype filter.
This adds a few more common compressed filetypes to the is_compressed
fuction. Notably, xz, and two common package file formats, deb and rpm.
2017-08-07 00:57:29 -04:00
Benjamin Sago
115315a03c Test the locale month name width stuff
This commit modifies a specific file timestamp so we test both July (which is 5 characters in French) and December (which is 4 characters in Japanese). It’s also kind of a test for locales as well.
2017-08-06 22:25:00 +01:00
Benjamin Sago
4cb28593fd Fix ISO time style xtest
This started failing because the behaviour was corrected in #250.
2017-08-06 20:42:15 +01:00
Benjamin Sago
dd0c5f6bef Merge pull request #250 from ogham/exa/issue-213
fix issue #213 iso date format inversion
2017-08-06 20:38:21 +01:00
Benjamin Sago
999c9d56f5 Merge pull request #247 from ogham/exa/date_output
Fix month name widths once and for all #244
2017-08-06 20:23:09 +01:00
Benjamin Sago
68210c5e8c Merge branch 'master' of github.com:ogham/exa 2017-08-06 17:59:10 +01:00
Benjamin Sago
40ce7ba0b7 Merge pull request #251 from ogham/exa/master
Add raw file type for Olympus and Nikon
2017-08-06 17:56:04 +01:00
Benjamin Sago
89540edb22 Allow xattrs to be shown in --tree without --long
This restriction was originally only there because a standalone --tree wasn’t a thing. Now it’s there, there’s no reason to forbid the combination.
2017-08-06 12:02:17 +01:00
Nontawat Numor
e43e288d19 Add raw file type for Olympus and Nikon 2017-08-06 17:47:15 +07:00
Alfred Sawaya
fca5b6b970 fix issue #213 iso date format inversion 2017-08-06 12:36:00 +02:00
Alfred Sawaya
cb2e94a796 Fix month name widths once and for all #244
To render the date, Exa now find out the month with the longest name
among all months, and use the width of that.
2017-08-06 03:59:46 +02:00
Benjamin Sago
b5bcf22612 Merge remote-tracking branch origin/option-pars-ng
This merges in exa’s own new options parser, which has the following features:

- You can specify an option twice and it’ll use the second one, making aliases usable for defaults (fixes #144)
- Lets arguments be specified more than once (fixes #125)

Strict mode is not done yet; I just wanted to merge this in because it’s been a while, and there’s work that needs to be done on master so I don’t want them drifting apart any further.

It’s likely that you’ll find cases where multiple arguments doesn’t work or where the wrong value is being used. There aren’t tests for *everything* yet, and it still uses global environment variables.

# Conflicts:
#	src/options/view.rs
2017-08-05 21:34:57 +01:00
Benjamin Sago
ad8c3c4323 Specify minimum compiler version
Now I just need to remember to update it. Was suggested in #197.
2017-08-05 20:31:39 +01:00
Benjamin Sago
4289f4d27e Specify that we need the width of stdout
The term_size crate introduced in #237 did things *slightly* differently than exa: it tried to get the terminal width of stdout, stderr, and stdin. This broke some tests that only redirected stdout.
2017-08-05 20:26:13 +01:00
Benjamin Sago
d701547ec4 Merge pull request #237 from ogham/exa/term_size
Use term_size crate to fetch terminal size.
2017-08-05 20:08:06 +01:00
Benjamin Sago
878be362c6 Merge pull request #224 from ogham/exa/master
Update filetype.rs
2017-08-05 19:58:19 +01:00
Benjamin Sago
6759a5f97e Temporarily hush warnings 2017-08-05 19:56:42 +01:00
Benjamin Sago
7cb9a43541 Extract version info into its own struct
Now it’s more like help. There aren’t any other fields in its struct at the moment, but there will be in the future (listing the features, and extremely colourful vanity mode)
2017-08-05 19:46:47 +01:00
Benjamin Sago
411bdc4321 These help fields don’t need to be pub 2017-08-05 19:45:55 +01:00
Benjamin Sago
cdad6bb960 Make building the matches more bearable
Now, building the two result vectors doesn’t have to go through at least one field.
2017-08-05 19:15:27 +01:00
Benjamin Sago
9872eba821 Separate the matched flags from the free strings
Originally, both the matched flags and the list of free strings were returned from the parsing function and then passed around to every type that had a ‘deduce’ method. This worked, but the list of free strings was carried around with it, never used.

Now, only the flags are passed around. They’re in a new struct which has the methods the Matches had.

Both of Matches’s fields are now just data, and all of the methods on MatchedFlags don’t ignore any fields, so it’s more cohesive, at least I think that’s the word.

Building up the MatchedFlags is a bit more annoying though because the vector is now hidden behind a field.
2017-08-05 19:11:00 +01:00
Benjamin Sago
0456e7cfbd Document and organise the parser module 2017-08-05 17:46:38 +01:00