From 5aa8100a48b8b6c74d3bffed7430eaeb4ee98753 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 3 Aug 2011 20:53:20 +0000 Subject: Added a command line script to ~/tools to count... Added a command line script to ~/tools to count flag usages. I'm checking this in less out of the enormous demand for flag counting scripts than because I wanted to lower the barrier to people writing reusable bash scripts. *** DO YOU WANT TO WRITE NICE BASH SCRIPTS? *** *** Look at tools/flag-usages.sh *** *** It's easy to understand and full of helpful comments! *** I'm not making any claims here about having massive bash expertise, but I know a lot of people resist learning any of it (I was once like you) so I wanted to lower the barrier a little. Because as a mechanism for the composition and modification of the world of existing tools, nothing comes close to the shell. And I know many of us write way too many one-offs which we delete in shame and horror shortly after their immediate purpose is served. No review. (I should say r-e-v-i-e-w by everyone but I'm sure it would give me a nice pile of crucible errors.) --- tools/flag-usages.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 tools/flag-usages.sh (limited to 'tools/flag-usages.sh') diff --git a/tools/flag-usages.sh b/tools/flag-usages.sh new file mode 100755 index 0000000000..82696bd1da --- /dev/null +++ b/tools/flag-usages.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# +# find-flag-usages +# Paul Phillips +# +# Looks through the scala source tree for direct references to flag names. + +set -e # Good idea in almost all scripts: causes script to exit on any error. + +# Would be better not to hardcode this. +flags='\b(ABSOVERRIDE|ABSTRACT|ACCESSOR|BRIDGE|BYNAMEPARAM|CAPTURED|CASE|CASEACCESSOR|CONTRAVARIANT|COVARIANT|DEFAULTINIT|DEFAULTPARAM|DEFERRED|EXISTENTIAL|EXPANDEDNAME|FINAL|IMPLCLASS|IMPLICIT|INCONSTRUCTOR|INTERFACE|JAVA|LABEL|LAZY|LIFTED|LOCAL|LOCKED|METHOD|MIXEDIN|MODULE|MODULEVAR|MUTABLE|OVERLOADED|OVERRIDE|PACKAGE|PARAM|PARAMACCESSOR|PRESUPER|PRIVATE|PROTECTED|SEALED|SPECIALIZED|STABLE|STATIC|SUPERACCESSOR|SYNTHETIC|TRAIT|TRIEDCOOKING|VARARGS|VBRIDGE)\b' + +# $() runs a command in a subshell. This is calculating the root of the +# repository by looking relative to the location of the script. +rootdir=$(cd $(dirname $0) ; pwd)/.. + +# A bash function. Can be used like a command. +usage () { + # A here string. Allows for blocks of text without lots of quoting. + # Variable interpolation still takes place, e.g. $(basename $0). + cat </dev/null + +# The leading : in :achs suppresses some errors. Each letter is a valid +# option. If an option takes an argument, a colon follows it, e.g. +# it would be :ach:s if -h took an argument. +while getopts :achs opt; do + case $opt in + a) ack "$flags" src ;; + c) ack --files-with-matches -c "$flags" src ;; + h) usage ;; + s) ack --no-filename -o "$flags" src | sort | uniq -c | sort -gr ;; + :) echo "Option -$OPTARG requires an argument." >&2 ;; # this case is called for a missing option argument + *) echo "Unrecognized argument $OPTARG" ;; # this is the catch-all implying an unknown option + esac +done + +# This removes all the options from $@, as getopts doesn't touch it. +# After this, "$@" contains the non-option arguments. +shift $((OPTIND-1)) + +# In this program we don't expect any. +if [[ $# -ne 0 ]]; then + echo "This program does not take arguments." +fi + +popd >/dev/null +exit 0 -- cgit v1.2.3