Skip to content

Commit

Permalink
Merge pull request #26 from jaimebuelta/env_variables
Browse files Browse the repository at this point in the history
Env variables
  • Loading branch information
jaimebuelta committed Aug 11, 2017
2 parents 8e0d7e8 + bd7783d commit f19212a
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 39 deletions.
46 changes: 39 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,23 @@ All options

optional arguments:
-h, --help show this help message and exit
-p Match whole path, not only name of files
--nocolor Do not display color
-p Match whole path, not only name of files. Set env
variable FFIND_SEARCH_PATH to set this automatically
--nocolor Do not display color. Set env variable FFIND_NO_COLOR
to set this automatically
--nosymlinks Do not follow symlinks (following symlinks can lead to
infinite recursion)
--hidden Do not ignore hidden directories
infinite recursion) Set env variable FFIND_NO_SYMLINK
to set this automatically
--hidden Do not ignore hidden directories. Set env variable
FFIND_SEARCH_HIDDEN to set this automatically
-c Force case sensitive. By default, all lowercase
patterns are case insensitive
patterns are case insensitive. Set env variable
FFIND_CASE_SENSITIVE to set this automatically
-i Force case insensitive. This allows case insensitive
for patterns with uppercase. If both -i and -c are
set, the search will be case sensitive.
set, the search will be case sensitive.Set env
variable FFIND_CASE_INSENSITIVE to set this
automatically
--delete Delete files found
--exec "command" Execute the given command with the file found as
argument. The string '{}' will be replaced with the
Expand All @@ -79,12 +86,37 @@ All options
used, ffind will return a status code of 1 if any
exceptions occur, and 0 otherwise. SystemExit is not
caught
--ignore-vcs Ignore version control system files and directories
--ignore-vcs Ignore version control system files and directories.
Set env variable FFIND_IGNORE_VCS to set this
automatically
-f Experimental fuzzy search. Increases the matches, use
with care. Combining it with regex may give crazy
results
--return-results For testing purposes only. Please ignore
--version show program's version number and exit

Environment variables
---

Setting these environment variables, you'll set options by default. For example:

export FFIND_CASE_SENSITIVE=1
# equivalent to ffind -c something
ffind something
FFIND_CASE_SENSITIVE=1 ffind something

- FFIND_SORT: Return the results sorted. This is slower, and is mainly thought to ensure
consistency on the tests, as some filesystems may order files differently
- FFIND_CASE_SENSITIVE: Search is case sensitive. Equivalent to -c flag
- FFIND_CASE_INSENSITIVE: Search is case insensitive. Equivalent to -i flag.
- FFIND_SEARCH_HIDDEN: Search in hidden directories. Equivalent to --hidden flag.
- FFIND_SEARCH_PATH: Search in the whole path. Equivalent to -p flag.
- FFIND_IGNORE_VCS: Ignore paths in version control. Equivalent to --ignore-vcs
- FFIND_NO_SYMLINK: Do not follow symlinks. Equivalent to --nosymlinks flag.
- FFIND_NO_COLOR: Do not show colors. Equivalent to --nocolor flag.

If the environment is present, when calling ffind -h, the option will display [SET] at the end.


Install
---
Expand Down
69 changes: 55 additions & 14 deletions ffind/ffind.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,42 +290,78 @@ def parse_params_and_search():
parser = argparse.ArgumentParser(
description='Search file name in directory tree'
)

env_var = bool(os.environ.get('FFIND_SEARCH_PATH'))
parser.add_argument('-p',
action='store_true',
help='Match whole path, not only name of files',
help='Match whole path, not only name of files. '
'Set env variable FFIND_SEARCH_PATH to set '
'this automatically'
'{0}'.format('[SET]' if env_var else ''),
dest='path_match',
default=False)
# default False
default=env_var)

env_var = bool(os.environ.get('FFIND_NO_COLOR'))
parser.add_argument('--nocolor',
action='store_false',
dest='colored',
help='Do not display color',
default=True)
help='Do not display color. '
'Set env variable FFIND_NO_COLOR to set '
'this automatically'
'{0}'.format('[SET]' if env_var else ''),
# default True
default=not env_var)

env_var = bool(os.environ.get('FFIND_NO_SYMLINK'))
parser.add_argument('--nosymlinks',
action='store_false',
dest='follow_symlinks',
help='Do not follow symlinks'
' (following symlinks can lead to '
'infinite recursion)',
default=True)
'infinite recursion) '
'Set env variable FFIND_NO_SYMLINK to set '
'this automatically'
'{0}'.format('[SET]' if env_var else ''),
# default True
default=not env_var)

env_var = bool(os.environ.get('FFIND_SEARCH_HIDDEN'))
parser.add_argument('--hidden',
action='store_false',
dest='ignore_hidden',
help='Do not ignore hidden directories',
default=True)
help='Do not ignore hidden directories. '
'Set env variable FFIND_SEARCH_HIDDEN to set '
'this automatically'
'{0}'.format('[SET]' if env_var else ''),
# default is True
default=not env_var)

env_var = bool(os.environ.get('FFIND_CASE_SENSITIVE'))
parser.add_argument('-c',
action='store_true',
dest='case_sensitive',
help='Force case sensitive. By default, all lowercase '
'patterns are case insensitive',
default=False)
'patterns are case insensitive. '
'Set env variable FFIND_CASE_SENSITIVE to set '
'this automatically'
'{0}'.format('[SET]' if env_var else ''),
# default is False
default=env_var)

env_var = bool(os.environ.get('FFIND_CASE_INSENSITIVE'))
parser.add_argument('-i',
action='store_true',
dest='case_insensitive',
help='Force case insensitive. This allows case '
'insensitive for patterns with uppercase. '
'If both -i and -c are set, the search will be '
'case sensitive.',
default=False)
'case sensitive.'
'Set env variable FFIND_CASE_INSENSITIVE to set '
'this automatically'
'{0}'.format('[SET]' if env_var else ''),
# default is False
default=env_var)

action = parser.add_mutually_exclusive_group()

Expand Down Expand Up @@ -368,12 +404,17 @@ def parse_params_and_search():
'and 0 otherwise. SystemExit is not caught',
default=False)

env_var = bool(os.environ.get('FFIND_IGNORE_VCS'))
parser.add_argument('--ignore-vcs',
action='store_true',
dest='ignore_vcs',
help='Ignore version control system files and '
'directories',
default=False)
'directories. '
'Set env variable FFIND_IGNORE_VCS to set '
'this automatically'
'{0}'.format('[SET]' if env_var else ''),
# Default False
default=env_var)

parser.add_argument('-f',
action='store_true',
Expand Down
57 changes: 50 additions & 7 deletions man_pages/ffind.1
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,23 @@ positional arguments:

optional arguments:
\-h, \-\-help show this help message and exit
\-p Match whole path, not only name of files
\-\-nocolor Do not display color
\-p Match whole path, not only name of files. Set env
variable FFIND_SEARCH_PATH to set this automatically
\-\-nocolor Do not display color. Set env variable FFIND_NO_COLOR
to set this automatically
\-\-nosymlinks Do not follow symlinks (following symlinks can lead to
infinite recursion)
\-\-hidden Do not ignore hidden directories
infinite recursion) Set env variable FFIND_NO_SYMLINK
to set this automatically
\-\-hidden Do not ignore hidden directories. Set env variable
FFIND_SEARCH_HIDDEN to set this automatically
\-c Force case sensitive. By default, all lowercase
patterns are case insensitive
patterns are case insensitive. Set env variable
FFIND_CASE_SENSITIVE to set this automatically
\-i Force case insensitive. This allows case insensitive
for patterns with uppercase. If both \-i and \-c are
set, the search will be case sensitive.
set, the search will be case sensitive.Set env
variable FFIND_CASE_INSENSITIVE to set this
automatically
\-\-delete Delete files found
\-\-exec "command" Execute the given command with the file found as
argument. The string '{}' will be replaced with the
Expand All @@ -91,13 +98,49 @@ optional arguments:
used, ffind will return a status code of 1 if any
exceptions occur, and 0 otherwise. SystemExit is not
caught
\-\-ignore\-vcs Ignore version control system files and directories
\-\-ignore\-vcs Ignore version control system files and directories.
Set env variable FFIND_IGNORE_VCS to set this
automatically
\-f Experimental fuzzy search. Increases the matches, use
with care. Combining it with regex may give crazy
results
\-\-return\-results For testing purposes only. Please ignore
\-\-version show program's version number and exit
.fi
.RE
.SH Environment variables
.PP
Setting these environment variables, you'll set options by default. For example:
.PP
.RS
.nf
export FFIND_CASE_SENSITIVE=1
# equivalent to ffind \-c something
ffind something
FFIND_CASE_SENSITIVE=1 ffind something
.fi
.RE
.RS
.IP \(bu 2
FFIND_SORT: Return the results sorted. This is slower, and is mainly thought to ensure
consistency on the tests, as some filesystems may order files differently
.IP \(bu 2
FFIND\fICASE\fPSENSITIVE: Search is case sensitive. Equivalent to \-c flag
.IP \(bu 2
FFIND\fICASE\fPINSENSITIVE: Search is case insensitive. Equivalent to \-i flag.
.IP \(bu 2
FFIND\fISEARCH\fPHIDDEN: Search in hidden directories. Equivalent to \-\-hidden flag.
.IP \(bu 2
FFIND\fISEARCH\fPPATH: Search in the whole path. Equivalent to \-p flag.
.IP \(bu 2
FFIND\fIIGNORE\fPVCS: Ignore paths in version control. Equivalent to \-\-ignore\-vcs
.IP \(bu 2
FFIND\fINO\fPSYMLINK: Do not follow symlinks. Equivalent to \-\-nosymlinks flag.
.IP \(bu 2
FFIND\fINO\fPCOLOR: Do not show colors. Equivalent to \-\-nocolor flag.
.RE
.PP
If the environment is present, when calling ffind \-h, the option will display [SET] at the end.
.SH Install
.PP
pip install ffind
Expand Down
43 changes: 35 additions & 8 deletions man_pages/ffind.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,23 @@ <h2 id="all-options">All options<a name="all-options" href="#all-options" class=

optional arguments:
-h, --help show this help message and exit
-p Match whole path, not only name of files
--nocolor Do not display color
-p Match whole path, not only name of files. Set env
variable FFIND_SEARCH_PATH to set this automatically
--nocolor Do not display color. Set env variable FFIND_NO_COLOR
to set this automatically
--nosymlinks Do not follow symlinks (following symlinks can lead to
infinite recursion)
--hidden Do not ignore hidden directories
infinite recursion) Set env variable FFIND_NO_SYMLINK
to set this automatically
--hidden Do not ignore hidden directories. Set env variable
FFIND_SEARCH_HIDDEN to set this automatically
-c Force case sensitive. By default, all lowercase
patterns are case insensitive
patterns are case insensitive. Set env variable
FFIND_CASE_SENSITIVE to set this automatically
-i Force case insensitive. This allows case insensitive
for patterns with uppercase. If both -i and -c are
set, the search will be case sensitive.
set, the search will be case sensitive.Set env
variable FFIND_CASE_INSENSITIVE to set this
automatically
--delete Delete files found
--exec "command" Execute the given command with the file found as
argument. The string '{}' will be replaced with the
Expand All @@ -63,11 +70,31 @@ <h2 id="all-options">All options<a name="all-options" href="#all-options" class=
used, ffind will return a status code of 1 if any
exceptions occur, and 0 otherwise. SystemExit is not
caught
--ignore-vcs Ignore version control system files and directories
--ignore-vcs Ignore version control system files and directories.
Set env variable FFIND_IGNORE_VCS to set this
automatically
-f Experimental fuzzy search. Increases the matches, use
with care. Combining it with regex may give crazy
results
--return-results For testing purposes only. Please ignore
--version show program's version number and exit
</code></pre>
<h2 id="install">Install<a name="install" href="#install" class="md2man-permalink" title="permalink"></a></h2><p>pip install ffind</p><h2 id="manual-install">Manual Install<a name="manual-install" href="#manual-install" class="md2man-permalink" title="permalink"></a></h2><p>python setup.py install</p><h2 id="test">Test<a name="test" href="#test" class="md2man-permalink" title="permalink"></a></h2><p>It requires to install <a href="https://bitheap.org/cram/">cram</a> (it can be installed with <code>pip install cram</code>)</p><p>To run all the tests, run <code>make test</code>. This runs the tests on both Python 2 and Python 3. Running just
<h2 id="environment-variables">Environment variables<a name="environment-variables" href="#environment-variables" class="md2man-permalink" title="permalink"></a></h2><p>Setting these environment variables, you&#39;ll set options by default. For example:</p><pre class="highlight plaintext"><code>export FFIND_CASE_SENSITIVE=1
# equivalent to ffind -c something
ffind something
FFIND_CASE_SENSITIVE=1 ffind something
</code></pre>

<ul>
<li>FFIND_SORT: Return the results sorted. This is slower, and is mainly thought to ensure
consistency on the tests, as some filesystems may order files differently</li>
<li>FFIND<em>CASE</em>SENSITIVE: Search is case sensitive. Equivalent to -c flag</li>
<li>FFIND<em>CASE</em>INSENSITIVE: Search is case insensitive. Equivalent to -i flag.</li>
<li>FFIND<em>SEARCH</em>HIDDEN: Search in hidden directories. Equivalent to --hidden flag.</li>
<li>FFIND<em>SEARCH</em>PATH: Search in the whole path. Equivalent to -p flag.</li>
<li>FFIND<em>IGNORE</em>VCS: Ignore paths in version control. Equivalent to --ignore-vcs</li>
<li>FFIND<em>NO</em>SYMLINK: Do not follow symlinks. Equivalent to --nosymlinks flag.</li>
<li>FFIND<em>NO</em>COLOR: Do not show colors. Equivalent to --nocolor flag.</li>
</ul>
<p>If the environment is present, when calling ffind -h, the option will display [SET] at the end.</p><h2 id="install">Install<a name="install" href="#install" class="md2man-permalink" title="permalink"></a></h2><p>pip install ffind</p><h2 id="manual-install">Manual Install<a name="manual-install" href="#manual-install" class="md2man-permalink" title="permalink"></a></h2><p>python setup.py install</p><h2 id="test">Test<a name="test" href="#test" class="md2man-permalink" title="permalink"></a></h2><p>It requires to install <a href="https://bitheap.org/cram/">cram</a> (it can be installed with <code>pip install cram</code>)</p><p>To run all the tests, run <code>make test</code>. This runs the tests on both Python 2 and Python 3. Running just
<code>make</code> runs the test for Python 3.</p><p>The tests are under the <code>tests</code> directory, more tests are welcome.</p>
20 changes: 20 additions & 0 deletions tests/case_sensitive.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,23 @@ Run test
$ $PYTHON $TESTDIR/../ffind/ffind.py -i -c Test2
./test_dir/Test2.py
./test_dir/second_level/sTest2.py


Run the tests with environment variables

$ $PYTHON $TESTDIR/../ffind/ffind.py test2
./test_dir/Test2.py
./test_dir/second_level/sTest2.py

$ FFIND_CASE_SENSITIVE=1 $PYTHON $TESTDIR/../ffind/ffind.py Test2
./test_dir/Test2.py
./test_dir/second_level/sTest2.py

$ FFIND_CASE_SENSITIVE=1 $PYTHON $TESTDIR/../ffind/ffind.py test2

$ FFIND_CASE_INSENSITIVE=1 $PYTHON $TESTDIR/../ffind/ffind.py STEST1
./test_dir/second_level/stest1.py

$ FFIND_CASE_SENSITIVE=1 FFIND_CASE_INSENSITIVE=1 $PYTHON $TESTDIR/../ffind/ffind.py Test2
./test_dir/Test2.py
./test_dir/second_level/sTest2.py
10 changes: 7 additions & 3 deletions tests/hidden.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ Setup

Run test

Ensure consistent sorting, as this depends on the filesystem

$ $PYTHON $TESTDIR/../ffind/ffind.py --hidden config | sort
$ $PYTHON $TESTDIR/../ffind/ffind.py --hidden config
./test_dir/.git/config
./test_dir/second_level/config
$ $PYTHON $TESTDIR/../ffind/ffind.py config
./test_dir/second_level/config
$ $PYTHON $TESTDIR/../ffind/ffind.py lib

Using environment variable

$ FFIND_SEARCH_HIDDEN=1 $PYTHON $TESTDIR/../ffind/ffind.py config
./test_dir/.git/config
./test_dir/second_level/config
Loading

0 comments on commit f19212a

Please sign in to comment.