#!/bin/bash

report_length=""

function usage
{
	retval="$1"
	case "$retval" in
		0)
			;;
		*)
			exec 1>&2
			;;
	esac
	
	echo "Usage: $0 --report-length 132 --help"
	echo
	echo 'Example usage might look like:'
	echo "    find ~ -name site-packages -prune -o -type f -name '*.py' -print0 | $0"

	exit "$retval"
}

while [ "$#" -ge 1 ]
do
	case "$1" in
		--report-length)
			report_length="$2"
			shift
			;;
		-h|--help)
			usage 0
			;;
		*)
			echo "$0: unrecognized option: $1" 1>&2
			usage 1
			;;
	esac
	shift
done

function rl
{
	case "$report_length" in
		'')
			;;
		*)
			echo --report-length "$report_length"
			;;
	esac
}

# shellcheck disable=SC2046
line-lengths $(rl) | mtee -s -q 'stddev' 'histogram --bin-function twentyfifth-ile'