Comments (4)
Added case *) for non-defined entries as a start.
from linux-serverbot.
This is added in nozel-org/serverbot@581f717. At first I was planning to add some rather advanced/extensive argument validation, where all exact combinations of possible commands are checked. But in the end I found this a little bit too much, so I will do it with two simple checks:
function requirement_argument_validity {
# amount of arguments less than one or more than two result in error
if [ "${#}" -eq '0' ] || [ "${#}" -gt '2' ]; then
error_invalid_option
fi
}
# other
*)
ARGUMENT_NONE='1'
shift
;;
elif [ "${ARGUMENT_NONE}" == '1' ]; then
error_invalid_option
fi
This will allow users to still use a combination of one valid single argument (i.e. --version
) and one invalid argument, but the script should still work fine in this scenario. Maybe there are better ways of doing this though.
from linux-serverbot.
Despite the last comment I wanted to improve it still, so I added:
function requirement_argument_validity {
# amount of arguments less than one or more than two result in error
if [ "${ARGUMENTS}" -eq '0' ] || [ "${ARGUMENTS}" -gt '2' ]; then
error_invalid_option
fi
# options are incompatible with features
if [ "${ARGUMENT_OPTION}" == '1' ] && [ "${ARGUMENT_FEATURE}" == '1' ]; then
error_invalid_option
fi
# options are incompatible with methods
if [ "${ARGUMENT_OPTION}" == '1' ] && [ "${ARGUMENT_METHOD}" == '1' ]; then
error_invalid_option
fi
}
And in the case loop all features, methods and options will populate the variables with 1.
from linux-serverbot.
Extended it further:
function requirement_argument_validity {
# amount of arguments less than one or more than two result in error
if [ "${ARGUMENTS}" -eq '0' ] || [ "${ARGUMENTS}" -gt '2' ]; then
error_wrong_number_of_arguments
fi
# options are incompatible with features
if [ "${ARGUMENT_OPTION}" == '1' ] && [ "${ARGUMENT_FEATURE}" == '1' ]; then
error_options_cannot_be_combined
fi
# options are incompatible with methods
if [ "${ARGUMENT_OPTION}" == '1' ] && [ "${ARGUMENT_METHOD}" == '1' ]; then
error_options_cannot_be_combined
fi
# if there are two arguments, only a combination of feature and method is possible
if [ "${ARGUMENTS}" -eq '2' ]; then
# features require methods and vice versa, so they should add to two.
ARGUMENT_FEATURE_AND_METHOD="$((${ARGUMENT_FEATURE}+${ARGUMENT_METHOD}))"
# and otherwise result in an error
if [ "${ARGUMENT_FEATURE_AND_METHOD}" -ne '2' ]; then
error_no_feature_and_method
fi
fi
}
from linux-serverbot.
Related Issues (20)
- Remove useless comments HOT 1
- Layout issue in feature updates on method telegram HOT 1
- Fix wrong variable in cron function HOT 1
- No error when method telegram is unavailable HOT 1
- Move all gather functions from serverbot_main HOT 1
- Variable branch in serverbot.sh HOT 1
- Method: local log
- Conflicting argument shortcuts HOT 2
- Feature updates method cli still uses breaks HOT 1
- Option --upgrade error n: command not found HOT 1
- Remove use of google.com HOT 2
- Add non-existent variables to validation variables HOT 1
- /dev/fd/63 error on sourcing remote file HOT 3
- Feature audit HOT 1
- SERVERBOT_BRANCH becomes first character of branch variable HOT 1
- Bug in feature updates with dnf on CentOS 8 HOT 1
- Feature overview extend with both IPv4 and IPv6 HOT 1
- Consider using hippocratic ethical license
- Fedora 30 doesn't have cron automatically installed
- Rename this project to linux-serverbot to distinguis from freebsd-serverbot
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from linux-serverbot.