From ff17b1eff5bcf0df371dfff009437229890ed429 Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Sat, 24 Oct 2020 17:33:20 -0700 Subject: [PATCH] search.find_files: fix option handling between pattern and directory parameters --- file_scripts/search.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/file_scripts/search.py b/file_scripts/search.py index 18c3252..01e0726 100644 --- a/file_scripts/search.py +++ b/file_scripts/search.py @@ -55,9 +55,25 @@ def find_files( cmd = [bin_override if bin_override is not None else FIND_CMD, *opts] cmd.append("--") - if pattern is not None: - cmd.append(pattern) - cmd.append(directory if directory is not None else ".") + + """ Options Matrix + pattern T T F F + directory T F T F + 1 2 3 4 + + 1. Pattern and directory were given: pass both + 2. Only pattern was given: pass pattern and give . as directory + 3. Only directory was given: pass . as pattern and give directory + 4. Neither pattern nor directory were given: do nothing + """ + if pattern is not None and directory is not None: + cmd.extend([pattern, directory]) + elif pattern is not None and directory is None: + cmd.extend([pattern, "."]) + elif pattern is None and directory is not None: + cmd.extend([".", directory]) + elif pattern is None and directory is None: + pass return subprocess.run(cmd, capture_output=True, text=capture_text).stdout