mirror of
https://github.com/arkenfox/user.js.git
synced 2025-05-07 17:33:45 +02:00
Improve parsing of command line options
This commit is contained in:
parent
d821c49625
commit
d215dea5b0
1 changed files with 46 additions and 10 deletions
56
updater.sh
56
updater.sh
|
@ -5,17 +5,23 @@
|
||||||
# Copyright (C) 2018 Emanuele Petriglia <inbox@emanuelepetriglia.me>.
|
# Copyright (C) 2018 Emanuele Petriglia <inbox@emanuelepetriglia.me>.
|
||||||
# All right reserved. This file is licensed under the MIT license.
|
# All right reserved. This file is licensed under the MIT license.
|
||||||
#
|
#
|
||||||
|
# Special requirements (beyond Bash): wget and mktemp.
|
||||||
|
#
|
||||||
# Version: 1.4
|
# Version: 1.4
|
||||||
#
|
#
|
||||||
# Please read the wiki or run 'updater.sh --help' to get informations about this
|
# Please read the wiki or run 'updater.sh --help' to get informations about this
|
||||||
# script.
|
# script.
|
||||||
|
#
|
||||||
|
# Report bugs to https://github.com/ghacksuserjs/ghacks-user.js/issues
|
||||||
|
|
||||||
|
readonly VERSION="1.4"
|
||||||
|
|
||||||
# Default values for flags.
|
# Default values for flags.
|
||||||
QUIET="false"
|
QUIET="false"
|
||||||
VERBOSE="false"
|
VERBOSE="false"
|
||||||
FORCE_VERSION="false"
|
FORCE_VERSION="false"
|
||||||
UPDATED="false"
|
UPDATED="false"
|
||||||
VERSION="1.4"
|
|
||||||
|
|
||||||
# Prints a message to the standard error and exit with error code 1.
|
# Prints a message to the standard error and exit with error code 1.
|
||||||
error() {
|
error() {
|
||||||
|
@ -73,6 +79,8 @@ Options:
|
||||||
--help Print this message
|
--help Print this message
|
||||||
--version Print script version
|
--version Print script version
|
||||||
|
|
||||||
|
Please run this script from your Firefox profile directory.
|
||||||
|
|
||||||
Please note that it is not given the option '--force-version' this script will
|
Please note that it is not given the option '--force-version' this script will
|
||||||
download the latest version available, that can be unstable.
|
download the latest version available, that can be unstable.
|
||||||
|
|
||||||
|
@ -87,11 +95,12 @@ show_version() {
|
||||||
|
|
||||||
# Updates the user.js.
|
# Updates the user.js.
|
||||||
update_userjs() {
|
update_userjs() {
|
||||||
# Run the recenlty downloader version of this script.
|
# Run the recently downloader version of this script.
|
||||||
if [[ "$UPDATED" == "true" ]]; then
|
if [[ "$UPDATED" == "true" ]]; then
|
||||||
source "$PROGRAM" $@
|
source "$PROGRAM" $@
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
echo "aggiornato"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if a program is installed. If it is not installed prints an error.
|
# Check if a program is installed. If it is not installed prints an error.
|
||||||
|
@ -106,14 +115,41 @@ PROGRAM="${0##*/}"
|
||||||
check_utily "wget"
|
check_utily "wget"
|
||||||
check_utily "mktemp"
|
check_utily "mktemp"
|
||||||
|
|
||||||
case "$1" in
|
UPDATE_INSTALLER="false"
|
||||||
--update|-u) shift; update_installer "$@";;
|
SHOW_HELP="false"
|
||||||
--force-version|-f) shift; FORCE_VERSION="yes";;
|
SHOW_VERSION="false"
|
||||||
--quiet|-q) shift; QUIET="yes";;
|
|
||||||
--verbose) shift; VERBOSE="true";;
|
# Parse command line options.
|
||||||
--help|-h) shift; show_help;;
|
while :; do
|
||||||
--version|-v) shift; show_version;;
|
case "$1" in
|
||||||
esac
|
--update|-u) shift; UPDATE_INSTALLER="true";;
|
||||||
|
--force-version|-f) shift; FORCE_VERSION="true";;
|
||||||
|
--quiet|-q) shift; QUIET="true";;
|
||||||
|
--verbose) shift; VERBOSE="true";;
|
||||||
|
--help|-h) shift; SHOW_HELP="true";;
|
||||||
|
--version|-v) shift; SHOW_VERSION="true";;
|
||||||
|
"") break;; # Default case: no more options.
|
||||||
|
*) error "Unrecognized option '$1'";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$VERBOSE" == "true" && "$QUIET" == "true" ]]; then
|
||||||
|
error "You can't use '--verbose' and '--quiet' options together"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$SHOW_HELP" == "true" ]]; then
|
||||||
|
show_help
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$SHOW_VERSION" == "true" ]]; then
|
||||||
|
show_version
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$UPDATE_INSTALLER" == "true" ]]; then
|
||||||
|
update_installer
|
||||||
|
fi
|
||||||
|
|
||||||
update_userjs
|
update_userjs
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue