cli now supports --long-opts. improved help / usage information

This commit is contained in:
Patrick Stadler 2015-03-15 10:01:41 +01:00
parent ca25c6d7fe
commit 98c83e4af5
8 changed files with 43 additions and 27 deletions

View File

@ -1,10 +1,8 @@
## TODO
- README
- improve CLI interface
- allow multiple reporters
- better docs, including reporters (--docs)
- config file support
- config file auto-generation
- load custom/contrib metrics and reporters
- same metric multiple times (e.g. disk_usage for multiple devices)
- same metric multiple times? (e.g. disk_usage for multiple devices)
- allow multiple reporters?

View File

@ -2,7 +2,7 @@
# config
INTERVAL=2
REPORTER=stdout # TODO: handle multiple reporters
REPORTER=stdout
# env
LC_ALL=en_US.UTF-8
@ -19,34 +19,52 @@ usage () {
}
help () {
echo "TODO"
echo
usage
echo
echo " Options: "
echo
echo " -r, --reporter <reporter> use specified reporter (default: stdout)"
echo " -i, --interval <seconds> collect metrics every n seconds (default: 2)"
echo " -v, --verbose enable verbose mode"
echo " -d, --docs show documentation"
echo " -h, --help show this text"
echo
}
while getopts "$opts_spec" opt; do
case "${opt}" in
d)
while [ $# -gt 0 ]; do
case $1 in
-r|--reporter)
shift
REPORTER=$1
;;
-i|--interval)
shift
INTERVAL=$1
;;
-v|-verbose)
opt_verbose=true
;;
-d|--docs)
opt_docs=true
;;
h)
-h|--help)
help
exit
;;
v)
opt_verbose=true
;;
r)
REPORTER=$OPTARG
;;
i)
INTERVAL=$OPTARG
;;
*)
usage
exit 1
;;
esac
shift
done
shift $((OPTIND-1))
# run

View File

@ -37,5 +37,5 @@ terminate () {
docs () {
echo "Disk I/O in MB/s."
echo "\$DISK_IO_MOUNTPOINT=$DISK_IO_MOUNTPOINT"
echo "\$DISK_IO_MOUNTPOINT="
}

View File

@ -17,5 +17,5 @@ collect () {
docs () {
echo "Disk usage percentage for a file system at a given mount point."
echo "\$DISK_USAGE_MOUNTPOINT=$DISK_USAGE_MOUNTPOINT"
echo "\$DISK_USAGE_MOUNTPOINT="
}

View File

@ -39,5 +39,5 @@ collect () {
docs () {
echo "Network traffic in kB/s."
echo "\$NETWORK_IO_INTERFACE=$NETWORK_IO_INTERFACE"
echo "\$NETWORK_IO_INTERFACE="
}

View File

@ -20,5 +20,5 @@ report () {
docs () {
echo "Write to a file or named pipe."
echo "\$FILE_LOCATION=$FILE_LOCATION"
echo "\$FILE_LOCATION="
}

View File

@ -34,5 +34,5 @@ report () {
docs () {
echo "Send data to InfluxDB."
echo "\$INFLUXDB_API_ENDPOINT="
echo "\$INFLUXDB_SEND_HOSTNAME=$INFLUXDB_SEND_HOSTNAME"
echo "\$INFLUXDB_SEND_HOSTNAME=true"
}

View File

@ -33,5 +33,5 @@ docs () {
echo "Send data to Keen IO (https://keen.io)."
echo "\$KEEN_IO_WRITE_KEY=<write_key>"
echo "\$KEEN_IO_PROJECT_ID=<project_id>"
echo "\$KEEN_IO_EVENT_COLLECTION=$KEEN_IO_EVENT_COLLECTION"
echo "\$KEEN_IO_EVENT_COLLECTION=$HOSTNAME"
}