facelessuser/wcmatch

Maybe bring glob and fnmatch options into alignment

facelessuser opened this issue · 4 comments

Current defaults for glob and fnmatch vary quite a bit. Maybe make them align more for less confusion. If this was done, it would be as a major release.

Originally the idea was to match Python's fnmatch, which is why the defaults for that are off by default. Then when developing the glob portion, we decided to use the existing test suite from minimatch (which models bash behavior). It was easiest to just use their defaults which enables a number of the "extra" features by default. In retrospect a more consistent behavior may make more sense.

The question is, what does consistent mean? Do we disable more features in glob by default? Do we enable more features in fnmatch by default. I don't think this should affect wcmatch though, but we'll see.

So I think we will make glob model bash's default behavior which has extglob and globstar off by default, this also models our fnmatch and wcmatch lib. We will also require brace to be turned on if it is desired like our other modules require.

Though the official fnmatch lib usually refers to the extended match patterns as EXTMATCH and the official glob lib usually refers to the same patterns as EXTGLOB, for consistency, we will call it EXTGLOB everywhere.

The final question is do we change PERIOD in fnmatch to DOTGLOB which has the opposite effect? Or do we just leave PERIOD as is?

So after mulling this around a bit more this is what is actually happening:

  1. fnmatch and glob will share dot logic. By default, both will disallow . to be targeted by special patterns such as *.

  2. All libraries that support DOTGLOB will allow the flag DOTGLOB or DOTMATCH as some may be familiar with one for glob or fnmatch, but to the underlying library, there is no difference. Both aliases will set the same flag. There will be no PERIOD or NODOTGLOB.

  3. Like DOTGLOB, all libraries that support EXTGLOB will allow the flag EXTGLOB or EXTMATCH. EXTMATCH is usually associated with fnmatch while EXTGLOB is associated with glob. For users approaching this library, we will allow both so they can either use what they are familiar with, or use one for both. There will be no NOEXTGLOB. To the underlying library, there is no difference. Both aliases will set the same flag.

  4. Brace will always be off by default regardless of the library, so flags such as NOBRACE are removed in favor of BRACE.

Alright, last minute change of heart. Fnmatch will not allow EXTGLOB and DOTGLOB, but will only use the match variants. We already have the shorthand that can be used for consistency. Wcmatch will allow EXTGLOB, but only because the implementation conflicted with documentation, but it has been deprecated and will be removed in 3.0.0.

Technically, only glob will allow EXTGLOB and DOTGLOB moving forward as those are the names that Bash uses for glob, but he MATCH variants can also be used there for consistency.

In short, EXTMATCH and DOTMATCH are the consistent flag names, only glob allows GLOB variants, but wcmatch will temporarily allow GLOB variants due to a bug when implemented; docs stated EXTMATCH, but we were using EXTGLOB on accident.

Turns out I had the foresight to restrict Rummage to versions of wcmatch less than 2.0. We are going to actually rip the bandaide off in 2.0. The wcmatch.wcmatch lib will not have a deprecated EXTGLOB flag, it will just be EXTMATCH. Only glob will allow such variants which makes sense.