requirements/tools/code-search.sh
Tony Breeds 0592ee179b [tools] Add a tool to grep local repos
Sean wanted to know which repos still use mox/mox 3 which can be done
with this tool like:

tools/code-search.sh --prefix ~/projects/openstack/ \
                     --projects ~/projects/openstack/*/* \
                     -- mox origin/master -- *requirements.txt setup.cfg

The prefix is essentially a sting to remove from the project name.  So
the example above would change:

/home/tony/projects/openstack/openstack/astara => openstack/astara

Change-Id: I927bc96b6eafd2d95dc008b7f1a4374eb9f725b4
2018-01-10 11:59:08 +11:00

49 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
declare -a projects
in_projects=0
base=$HOME
while [ $# -gt 1 ] ; do
case "$1" in
--prefix)
prefix=$2
shift 1
;;
--projects)
in_projects=1
;;
--)
break
;;
*)
if [ "$in_projects" == 1 ] ; then
projects+=($1)
else
echo Unknown arg/context >&2
exit 1
fi
;;
esac
shift 1
done
for prj in ${projects[@]} ; do
(
cd $prj>/dev/null 2>&1 && \
git grep -HEin $@ 2>/dev/null|sed -e "s,^,${prj#$prefix}:,g"
)
done