changeset 312:f5f54b9c3552

treesum: Extensively improved "help patterns": - glob syntax rules - examples
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 10 Mar 2025 01:57:25 +0100
parents 6d1add815d14
children dbad01eb9d03
files cutils/util/fnmatch.py
diffstat 1 files changed, 116 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/cutils/util/fnmatch.py	Mon Mar 10 01:45:09 2025 +0100
+++ b/cutils/util/fnmatch.py	Mon Mar 10 01:57:25 2025 +0100
@@ -19,17 +19,125 @@
 from . import glob
 
 
-HELP_DESCRIPTION = """\
+HELP_DESCRIPTION = r"""
 PATTERNs
 ========
 
-  glob: case-sensitive, anchored at the begin and end
-  iglob: case-insensitive variant of "glob"
-  re: regular expression
-  path: plain text example (rooted), can be a file or a directory or a prefix
-        thereof
-  fullpath: exactly a single full path (file or directory), relative to the
-            root of the tree
+Filename matching allows several types of patterns. Each pattern starts
+with its type specification.
+
+  glob:
+    case-sensitive, anchored at the begin and end
+
+  iglob:
+    case-insensitive variant of "glob"
+
+  re:
+    regular expression (Python style)
+
+  path:
+    plain path name (rooted), can be a file or a directory or a prefix
+    thereof
+
+  fullpath:
+    exactly a single full path (file or directory), relative to the
+    root of the tree
+
+The default if no type is given explicitely is "glob:".
+
+
+Glob Syntax Rules
+-----------------
+
+- The `*' character matches zero or more characters of a name
+  component without crossing directory boundaries.
+
+- The `**' characters matches zero or more characters crossing
+  directory boundaries.
+
+- `**/' matches zero or more subdirectories; files do not match.
+
+- The `?' character matches exactly one character of a name component.
+
+- The backslash character (`\') is used to escape characters that
+  would otherwise be interpreted as special characters. The expression
+  `\\' matches a single backslash and `\{' matches a left brace for
+  example.
+
+- The `[ ]' characters are a bracket expression that match a single
+  character of a name component out of a set of characters. For example,
+  `[abc]' matches "a", "b", or "c". The hyphen (`-') may
+  be used to specify a range so `[a-z]' specifies a range that matches
+  from "a" to "z" (inclusive). These forms can be mixed so
+  `[abce-g]' matches "a", "b", "c", "e", "f" or "g".
+
+  If the character after the `[' is a `!' then it is used for negation
+  so `[!a-c]' matches any character except "a", "b", or "c".
+
+  Within a bracket expression the `*', `?' and `\' characters match
+  themselves.
+
+  The `-' character matches itself if it is the first or last character
+  within the brackets, or the first or last character after the `!' if
+  negating.
+
+  Also, the `]' character matches itself if it is the first character
+  within the brackets, or the first character after the `!' if negating.
+
+- The curly brace characters `{ }' denote a group of subpatterns, where
+  the group matches if any subpattern in the group matches.
+
+  The `,' character is used to separate the subpatterns. Groups can be
+  nested.
+
+- Leading period/dot characters in file name are treated as regular characters
+  in match operations. For example, the `*' glob pattern matches file name
+  `.login'.
+
+- All other characters match themselves.
+
+
+Examples
+--------
+
+  glob:*.py
+    any name ending with ".py" in the root directory
+
+  *.py
+    the same as "glob:*.py" (because "glob:" is the default)
+
+  re:\A[^/]*\.py\Z
+    the same as "glob:*.py"
+
+  glob:**.py
+    any name ending with ".py" anywhere
+
+  re:\.py\Z
+    the same as "glob:**.py"
+
+  glob:dir/*
+    any name in directory "dir"
+
+  Each of these patterns specify any name below directory "dir":
+
+    glob:dir/**
+
+    re:\Adir/
+
+    path:dir/
+
+  Each of these patterns specify any name in any directory that ends with
+  "file":
+
+    glob:**/file
+
+    re:(^|/)file\Z
+
+  These patterns specify a single path:
+
+    filepath:dir1/dir2/file
+
+    re:\Adir1/dir2/file\Z
 
 """