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 ## TODO
- README - README
- improve CLI interface
- allow multiple reporters
- better docs, including reporters (--docs)
- config file support - config file support
- config file auto-generation - config file auto-generation
- load custom/contrib metrics and reporters - 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 # config
INTERVAL=2 INTERVAL=2
REPORTER=stdout # TODO: handle multiple reporters REPORTER=stdout
# env # env
LC_ALL=en_US.UTF-8 LC_ALL=en_US.UTF-8
@ -15,38 +15,56 @@ opt_docs=false
opt_verbose=false opt_verbose=false
usage () { usage () {
echo "Usage: $0 [-d] [-h] [-v] [-r reporter] [-i interval]" echo " Usage: $0 [-d] [-h] [-v] [-r reporter] [-i interval]"
} }
help () { 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 while [ $# -gt 0 ]; do
case "${opt}" in case $1 in
d) -r|--reporter)
shift
REPORTER=$1
;;
-i|--interval)
shift
INTERVAL=$1
;;
-v|-verbose)
opt_verbose=true
;;
-d|--docs)
opt_docs=true opt_docs=true
;; ;;
h)
-h|--help)
help help
exit exit
;; ;;
v)
opt_verbose=true
;;
r)
REPORTER=$OPTARG
;;
i)
INTERVAL=$OPTARG
;;
*) *)
usage usage
exit 1 exit 1
;; ;;
esac esac
shift
done done
shift $((OPTIND-1))
# run # run

View File

@ -37,5 +37,5 @@ terminate () {
docs () { docs () {
echo "Disk I/O in MB/s." 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 () { docs () {
echo "Disk usage percentage for a file system at a given mount point." 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 () { docs () {
echo "Network traffic in kB/s." 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 () { docs () {
echo "Write to a file or named pipe." echo "Write to a file or named pipe."
echo "\$FILE_LOCATION=$FILE_LOCATION" echo "\$FILE_LOCATION="
} }

View File

@ -34,5 +34,5 @@ report () {
docs () { docs () {
echo "Send data to InfluxDB." echo "Send data to InfluxDB."
echo "\$INFLUXDB_API_ENDPOINT=" 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 "Send data to Keen IO (https://keen.io)."
echo "\$KEEN_IO_WRITE_KEY=<write_key>" echo "\$KEEN_IO_WRITE_KEY=<write_key>"
echo "\$KEEN_IO_PROJECT_ID=<project_id>" echo "\$KEEN_IO_PROJECT_ID=<project_id>"
echo "\$KEEN_IO_EVENT_COLLECTION=$KEEN_IO_EVENT_COLLECTION" echo "\$KEEN_IO_EVENT_COLLECTION=$HOSTNAME"
} }