diff --git a/tasks/easyoptions b/tasks/easyoptions index 1363a2e..22b86c7 100644 --- a/tasks/easyoptions +++ b/tasks/easyoptions @@ -2,7 +2,7 @@ ## ## EasyOptions 2015.2.28 Copyright (c) 2013, 2014 Renato Silva BSD licensed ## -## This script is supposed to parse command line arguments in a way that, even though its implementation is not trivial, it should be easy and smooth to use. +## This script is supposed to parse command line arguments in a way that, even though its implementation is not trivial, it should be easy and smooth to use. ## For using this script, simply document your target script using double-hash comments, like this: ## ## ## Program Name v1.0 Copyright (C) Someone @@ -20,23 +20,22 @@ ## ## --some-boolean This will get stored as some_boolean=yes. ## ## ## ## --some-value=VALUE This will get stored as some_value=VALUE, -## ## where VALUE is the actual value specified. The equal sign is optional and can be replaced with blank space. Short version +## ## where VALUE is the actual value specified. The equal sign is optional and can be replaced with blank space. Short version ## ## is not available in this format. ## -## The above comments work both as source code documentation and as help text, as well as define the options supported by your script. Parsing of the options -## from such documentation is quite slow, but at least there is not any duplication of the options specification. The string @#script.name will be replaced with +## The above comments work both as source code documentation and as help text, as well as define the options supported by your script. Parsing of the options +## from such documentation is quite slow, but at least there is not any duplication of the options specification. The string @#script.name will be replaced with ## the actual script name. ## -## After writing your documentation, you simply source this script. Then all command line options will get parsed into the corresponding variables, as described +## After writing your documentation, you simply source this script. Then all command line options will get parsed into the corresponding variables, as described ## above. You can then check their values for reacting to them. Regular arguments will be available in the $arguments array. ## -## In fact, this script is an example of itself. You are seeing this help message either because you are reading the source code, or you have called the script +## In fact, this script is an example of itself. You are seeing this help message either because you are reading the source code, or you have called the script ## in command line with the --help option. ## -## For better speed, you may want to define the options in source code yourself, so they do not need to be parsed from the documentation. The side effect is +## For better speed, you may want to define the options in source code yourself, so they do not need to be parsed from the documentation. The side effect is ## that when changing them, you will need to update both the documentation and the source code. You define the options statically like this: ## -## ## options=(o=option some-boolean some-value=?) ## show_error() { @@ -125,9 +124,6 @@ parse_options() { known_option_name=${known_option%=$known_option_var} # Short option if [[ "$option" = "$known_option_name" ]]; then - - # Short option - if [[ "$option" = "$known_option_name" ]]; then option_value="yes" known_option_var=$(echo "$known_option_var" | tr "-" "_") eval "$known_option_var=\"$option_value\"" @@ -164,8 +160,6 @@ parse_options() { done # Unknown option if [[ -z "$option_value" ]]; then - # Unknown option - if [[ -z "$option_value" ]]; then option=${option%%=*} [[ "$option" = \?* ]] && option=${option#*\?} show_error "unrecognized option -$option" @@ -180,5 +174,3 @@ parse_options() { done } parse_options "$@" - - diff --git a/tasks/easyoptions.LICENSE b/tasks/easyoptions.LICENSE index 2692674..f231ffa 100644 --- a/tasks/easyoptions.LICENSE +++ b/tasks/easyoptions.LICENSE @@ -1,6 +1,5 @@ -https://github.com/renatosilva/easyoptions -EasyOptions is distributed under the terms of the New BSD License (3-clause): Copyright (c) 2013, 2014 Renato Silva - All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +https://github.com/renatosilva/easyoptions EasyOptions is distributed under the terms of the New BSD License (3-clause): Copyright (c) 2013, 2014 Renato Silva + All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. @@ -9,10 +8,9 @@ following conditions are met: documentation and/or other materials provided with the distribution. * Neither the names of the copyright holders nor the names of the project contributors may be used to endorse or promote products derived from this - software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -