Skip to content

Commit

Permalink
Allow ^regexps as attachments patterns. Closes: #32
Browse files Browse the repository at this point in the history
  • Loading branch information
spanezz committed Jan 9, 2024
1 parent 5e4a0f2 commit 49e5444
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions a38tool
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,18 @@ class Allegati(App):
Show the attachments in the fattura
"""

def __init__(self, args):
def __init__(self, args: argparse.Namespace) -> None:
super().__init__(args)
self.pathname = args.file
self.ids: set[int] = set()
self.globs: list[re.pattern] = []
self.globs: list[re.Pattern] = []
self.has_filter = False
for pattern in self.args.attachments:
self.has_filter = True
if pattern.isdigit():
self.ids.add(int(pattern))
elif pattern.startswith("^"):
self.globs.append(re.compile(pattern))
else:
self.globs.append(re.compile(fnmatch.translate(pattern)))

Expand All @@ -448,7 +450,7 @@ class Allegati(App):
parser.add_argument(
"attachments",
nargs="*",
help="IDs or names of attachments to extract. Shell-like wildcards allowed",
help="IDs or names of attachments to extract. Shell-like wildcards allowed, or regexps if starting with ^",
)
return parser

Expand Down

0 comments on commit 49e5444

Please sign in to comment.