From ebbb5d379d6646de72fb74f016c6a75397def477 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Mon, 6 Jul 2015 09:28:56 +0100 Subject: [PATCH] Usage and deprecation warnings in script The usage is rearranged slightly to avoid wrapping at 80 characters. This will tend to overestimate warnings, since it doesn't try very hard to ignore values that are not intended to be options; in particular, arguments that are intended for `docker run`. (Using `--` to delimit these arguments would make this easier!) It does ignore values that follow known options though, for instance in weave -nickname "-password" (-nickname results in a deprecation warning, -password does not) and weave --password "-iprange" (no deprecation warning, since -iprange is ignored) --- weave | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 10 deletions(-) diff --git a/weave b/weave index 4b9e1b75..1b80bd88 100755 --- a/weave +++ b/weave @@ -26,19 +26,19 @@ CIDR_REGEXP="$IP_REGEXP/[0-9]{1,2}" usage() { echo "Usage:" echo "weave setup" - echo "weave launch [-password ] [-nickname ] [-nodiscovery]" - echo " [-iprange [-ipsubnet ]]" - echo " [-initpeercount ] ..." - echo "weave launch-router [-password ] [-nickname ] [-nodiscovery]" - echo " [-iprange [-ipsubnet ]]" - echo " [-initpeercount ] ..." + echo "weave launch [--password ] [--nickname ]" + echo " [--ipalloc-range [--ipalloc-default-subnet ]]" + echo " [--no-discovery] [--init-peer-count ] ..." + echo "weave launch-router [--password ] [--nickname ]" + echo " [--ipalloc-range [--ipalloc-default-subnet ]]" + echo " [--no-discovery] [--init-peer-count ] ..." echo "weave launch-dns []" echo "weave launch-proxy [-H ] [--with-dns | --without-dns]" - echo " [--no-default-ipalloc]" + echo " [--no-default-ipalloc]" echo "weave connect [--replace] [ ...]" echo "weave forget ..." echo "weave run [--with-dns | --without-dns] [ ...]" - echo " ..." + echo " ..." echo "weave start [ ...] " echo "weave attach [ ...] " echo "weave detach [ ...] " @@ -1100,6 +1100,83 @@ DOCKER_VERSION_MAJOR=$(echo "$DOCKER_VERSION" | cut -d. -f 1) DOCKER_VERSION_MINOR=$(echo "$DOCKER_VERSION" | cut -d. -f 2) DOCKER_VERSION_PATCH=$(echo "$DOCKER_VERSION" | cut -d. -f 3) +deprecation_warning() { + echo "Warning: ${1%=*} is deprecated; please use $2" >&2 +} + +deprecation_warnings() { + while [ $# -gt 0 ]; do + case "$1" in + -password|-password=*) + deprecation_warning $1 "--password" + [ "$1" == "-password" ] && shift + ;; + --password) + shift + ;; + -nickname|-nickname=*) + deprecation_warning $1 "--nickname" + [ "$1" == "-nickname" ] && shift + ;; + --nickname) + shift + ;; + -nodiscovery|--nodiscovery) + deprecation_warning $1 "--no-discovery" + ;; + -iprange|--iprange|-iprange=*|--iprange=*) + deprecation_warning $1 "--ipalloc-range" + [ ${1#--} == "iprange" ] && shift + ;; + --ipalloc-range) + shift + ;; + -ipsubnet|--ipsubnet|-ipsubnet=*|--ipsubnet=*) + deprecation_warning $1 "--ipalloc-default-subnet" + [ ${1#--} == "ipsubnet" ] && shift + ;; + --ipalloc-default-subnet) + shift + ;; + -initpeercount|--initpeercount|-initpeercount=*|--initpeercount=*) + deprecation_warning $1 "--init-peer-count" + [ ${1#--} == "initpeercount" ] && shift + ;; + --init-peer-count) + shift + ;; + -no-default-ipam|--no-default-ipam) + deprecation_warning $1 "--no-default-ipalloc" + ;; + --tlscacert|--tlscacert=*) + deprecation_warning "--tlscacert" "--tls-cacert" + [ "$1" == "--tlscacert" ] && shift + ;; + --tls-cacert) + shift + ;; + --tlscert|--tlscert=*) + deprecation_warning "--tlscert" "--tls-cert" + [ "$1" == "--tlscert" ] && shift + ;; + --tls-cert) + shift + ;; + --tlskey|--tlskey=*) + deprecation_warning "--tlskey" "--tls-key" + [ "$1" == "--tlskey" ] && shift + ;; + --tls-key) + shift + ;; + --tlsverify) + deprecation_warning "--tlsverify" "--tls-verify" + ;; + esac + shift + done +} + [ $# -gt 0 ] || usage COMMAND=$1 shift 1 @@ -1116,6 +1193,7 @@ case "$COMMAND" in create_bridge --without-ethtool ;; launch) + deprecation_warnings "$@" check_not_running $CONTAINER_NAME $BASE_IMAGE check_not_running $DNS_CONTAINER_NAME $BASE_DNS_IMAGE check_not_running $PROXY_CONTAINER_NAME $EXEC_IMAGE @@ -1125,6 +1203,7 @@ case "$COMMAND" in launch_proxy $COMMON_ARGS ;; launch-router) + deprecation_warnings "$@" check_not_running $CONTAINER_NAME $BASE_IMAGE launch_router "$@" echo $CONTAINER @@ -1135,16 +1214,17 @@ case "$COMMAND" in echo $DNS_CONTAINER ;; launch-proxy) + deprecation_warnings "$@" check_not_running $PROXY_CONTAINER_NAME $EXEC_IMAGE launch_proxy "$@" echo $PROXY_CONTAINER ;; env|proxy-env) - [ "$COMMAND" = "env" ] || echo "$COMMAND is deprecated, please use 'weave env'" >&2 + [ "$COMMAND" = "env" ] || deprecation_warning "$COMMAND" "'weave env'" proxy_addr "export DOCKER_HOST=" ;; config|proxy-config) - [ "$COMMAND" = "config" ] || echo "$COMMAND is deprecated, please use 'weave config'" >&2 + [ "$COMMAND" = "config" ] || deprecation_warning "$COMMAND" "'weave config'" proxy_addr "-H=" ;; connect)