find_files¶
Operation to search for text within files and return match file paths. Matching files
are stored in a list of matching_files, but the name can be specified using
output_name.
Example¶
The following example searches for qwikstart examples that use the shell operation:
examples/operations/find_files.yml¶steps:
"Find example files using shell operation":
name: find_files
path_filter: "*/examples/*.yml"
regex: "name: shell"
opconfig:
output_namespace: "template_variables"
"Choose example":
name: prompt
inputs:
- name: "example_file"
choices_from: "matching_files"
"Display example":
name: shell
cmd: "cat {{ qwikstart.example_file }}"
In addition to searching, this example takes the output of the search and passes it to
the prompt operation. Using the prompt input’s choices_from option allows the
user to select one of the matching_files found by find_files.
In order to use the matching_files output from the find_files operation, it’s saved
to the template_variables namespace by defining
output_namespace = "template_variables". See Understanding operations and
the docs for the prompt operation for more info.
To complete the example, the shell operation is used to print the contents of the file to the terminal.
Optional context¶
regexdefault:
''Regex to search for in files
directorydefault:
'.'Root directory for search (defaults to working directory).
output_namedefault:
'matching_files'Variable name where list of matching files is stored.
path_filterdefault:
NoneFile filter string passed to
fnmatchbefore searching. This can be used to speed up searching for large repositories.For example, you can limit text search to json files using
"*.json".regex_flagsList of Python regex flags. Any combination of
'IGNORECASE','MULTILINE','DOTALL','UNICODE'. See docs for Python regex library.
Output¶
This operation returns a list of file paths in a variable defined by output_name.