Skip to content

Commit

Permalink
fix minor problem in the handling of options and parameters
Browse files Browse the repository at this point in the history
options -A and -P have been replaced by -M anonymous and -M passport as
well
  • Loading branch information
phyver committed Nov 20, 2024
1 parent 9366d9e commit 0a90c74
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 89 deletions.
4 changes: 4 additions & 0 deletions i18n/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ msgstr "Error: a least one base function is not working properly.\n"
msgid "Error: couldn't get mission number $MISSION_NB (from $fn_name)"
msgstr "Error: couldn't get mission number $MISSION_NB (from $fn_name)"

#, sh-format
msgid "Error: invalid mode (option -M): '-$OPTARG'"
msgstr "Error: invalid mode (option -M): '-$OPTARG'"

#, sh-format
msgid "Error: invalid option: '-$OPTARG'"
msgstr "Error: invalid option: '-$OPTARG'"
Expand Down
4 changes: 4 additions & 0 deletions i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ msgstr "Erreur : au moins une fonction de base ne marche pas correctement.\n"
msgid "Error: couldn't get mission number $MISSION_NB (from $fn_name)"
msgstr "Error : mission '$MISSION_NB' introuvable (dans $fn_name)"

#, sh-format
msgid "Error: invalid mode (option -M): '-$OPTARG'"
msgstr "Erreur : mode invalide (option -M) : '-$OPTARG'"

#, sh-format
msgid "Error: invalid option: '-$OPTARG'"
msgstr "Erreur : option invalide: '-$OPTARG'"
Expand Down
4 changes: 4 additions & 0 deletions i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ msgstr "Errore: almeno una delle funzioni base non funziona correttamente.\n"
msgid "Error: couldn't get mission number $MISSION_NB (from $fn_name)"
msgstr "Errore: non é stato possibile ottenere il numero $MISSION_NB (da $fn_name)"

#, sh-format
msgid "Error: invalid mode (option -M): '-$OPTARG'"
msgstr ""

#, sh-format
msgid "Error: invalid option: '-$OPTARG'"
msgstr "Errore: opzione non valida: '-$OPTARG'"
Expand Down
9 changes: 5 additions & 4 deletions i18n/start-full-help/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ options:
-V display version
-I show list of available index files

-P passport mode: ask for name / emails of player
-A anonymous mode
-d debug mode
-D verbose debug mode
-M passport passport mode: ask for name / emails of player
-M anonymous anonymous mode
-M debug debug mode
-d alias for -M debug
-D verbose debug mode

-C continue current game (if relevant)
-R reset game
Expand Down
9 changes: 5 additions & 4 deletions i18n/start-full-help/fr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ options :
-V affiche la version
-I affiche la liste des fichier index disponibles

-P mode passeport : demande le nom / email du joueur
-D mode debug
-v lecture "verbeuse" des scripts de mission (seulement en mode debug)
-A mode anonyme
-M passport mode passeport : demande le nom / email du joueur
-M anonymous mode anonyme
-M debug mode debug
-d alias pour -M debug
-D mode debug verbeux

-C continue la partie en cours (si pertinent)
-R recommence une partie du début
Expand Down
9 changes: 5 additions & 4 deletions i18n/start-full-help/it.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ options:
-V mostra versione
-I ...

-P modalitá passaporto: chiede il nome/email del giocatore
-A modalitá anonima
-d modalitá debug
-D modalitá debug verbosa
-M passport modalitá passaporto: chiede il nome/email del giocatore
-M anonymous modalitá anonima
-M debug modalitá debug
-d modalitá debug
-D modalitá debug verbosa

-C continua la partita corrente (se rilevante)
-R reimposta la partita
Expand Down
4 changes: 4 additions & 0 deletions i18n/template.pot
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ msgstr ""
msgid "Error: couldn't get mission number $MISSION_NB (from $fn_name)"
msgstr ""

#, sh-format
msgid "Error: invalid mode (option -M): '-$OPTARG'"
msgstr ""

#, sh-format
msgid "Error: invalid option: '-$OPTARG'"
msgstr ""
Expand Down
153 changes: 88 additions & 65 deletions lib/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,75 +34,98 @@ GSH_EXEC_DIR=$(cd "$GSH_EXEC_DIR"; pwd -P)
# just in case
GSH_EXEC_DIR=${GSH_EXEC_DIR:-.}

while getopts ":hHInPdDACRXUVqGL:KBZc:FS:" opt
CHECK_SAVEFILE="true"

while getopts ":hHIndDM:CRXUVqL:KBZc:FS:" opt
do
case "$opt" in
V)
echo "Gameshell $GSH_VERSION"
if [ -n "$GSH_LAST_CHECKED_MISSION" ]
case "$opt" in
V)
echo "Gameshell $GSH_VERSION"
if [ -n "$GSH_LAST_CHECKED_MISSION" ]
then
echo "saved game: [mission $GSH_LAST_CHECKED_MISSION] OK"
fi
exit 0
;;
U)
TARGET="$GSH_EXEC_DIR/gameshell.sh"
TMPFILE="$GSH_EXEC_DIR/gameshell.sh$$"
if command -v wget >/dev/null
then
if wget -O "$TMPFILE" https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh
then
echo "saved game: [mission $GSH_LAST_CHECKED_MISSION] OK"
mv "$TMPFILE" "$TARGET"
chmod +x "$TARGET"
echo "Latest version of GameShell downloaded to $GSH_EXEC_DIR/gameshell.sh"
exit 0
else
rm -f "$TMPFILE"
echo "Error: couldn't download or save the latest version of GameShell." >&2
exit 1
fi
exit 0
;;
U)
TARGET="$GSH_EXEC_DIR/gameshell.sh"
TMPFILE="$GSH_EXEC_DIR/gameshell.sh$$"
if command -v wget >/dev/null
elif command -v curl >/dev/null
then
if curl -fo "$TMPFILE" https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh
then
if wget -O "$TMPFILE" https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh
then
mv "$TMPFILE" "$TARGET"
chmod +x "$TARGET"
echo "Latest version of GameShell downloaded to $GSH_EXEC_DIR/gameshell.sh"
exit 0
else
rm -f "$TMPFILE"
echo "Error: couldn't download or save the latest version of GameShell." >&2
exit 1
fi
elif command -v curl >/dev/null
then
if curl -fo "$TMPFILE" https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh
then
mv "$TMPFILE" "$TARGET"
chmod +x "$TARGET"
echo "Latest version of GameShell downloaded to $GSH_EXEC_DIR/gameshell.sh"
exit 0
else
rm -f "$TMPFILE"
echo "Error: couldn't download or save the latest version of GameShell." >&2
exit 1
fi
mv "$TMPFILE" "$TARGET"
chmod +x "$TARGET"
echo "Latest version of GameShell downloaded to $GSH_EXEC_DIR/gameshell.sh"
exit 0
else
rm -f "$TMPFILE"
echo "Error: couldn't download or save the latest version of GameShell." >&2
exit 1
fi
;;
X)
GSH_EXTRACT="true"
;;
K)
KEEP_DIR="true"
;;
F)
GSH_FORCE="true"
;;
h | H | I)
# used to avoid checking for more recent files
GSH_HELP="true"
;;
'?')
echo "$0: invalid option '-$OPTARG'" >&2
echo "use $0 -h to get the list of available options" >&2
exit 1
;;
:)
echo "$0: missing parameter for option '-$OPTARG'" >&2
echo "use $0 -h to get the list of available options" >&2
exit 1
;;
*)
# ignore other options, they will be passed to start.sh
;;
esac
fi
;;
X)
GSH_EXTRACT="true"
;;
K)
KEEP_DIR="true"
;;
F)
GSH_FORCE="true"
;;
h | H | I)
# used to avoid checking for more recent files
CHECK_SAVEFILE="false"
;;

S)
# the next cases are used to check validity of parameters, to avoid
# checking for savefiles the error message will be displayed with
# appropriate language by start.sh
case "$OPTARG" in
"index" | "simple" | "overwrite")
:
;;
*)
CHECK_SAVEFILE="false"
;;
esac
;;
M)
case "$OPTARG" in
passport | anonymous | debug)
:
;;
*)
CHECK_SAVEFILE="false"
;;
esac
;;

'?')
CHECK_SAVEFILE="false"
;;
:)
CHECK_SAVEFILE="false"
;;
*)
# ignore other options, they will be passed to start.sh
;;
esac
done


Expand All @@ -115,7 +138,7 @@ GSH_NAME=${GSH_NAME%-save*}
GSH_NAME=$(basename "$GSH_NAME")


if [ "$GSH_HELP" != "true" ] && [ "$GSH_FORCE" != "true" ]
if [ "$CHECK_SAVEFILE" = "true" ] && [ "$GSH_FORCE" != "true" ]
then
LAST_SAVEFILE=$(ls "$GSH_EXEC_DIR/$GSH_NAME-save"*".$EXT" 2>/dev/null | sort | tail -n 1)

Expand Down
22 changes: 16 additions & 6 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ GSH_EXPLICIT_LANGUAGE="false"
# if GSH_NO_GETTEXT is non-empty, gettext won't be used anywhere, the only language will thus be English
# export GSH_NO_GETTEXT=1 # DO NOT CHANGE OR REMOVE THIS LINE, it is used by utils/archive.sh
RESET=""
while getopts ":hHInPdDACRXUVqL:KBZc:FS:" opt
while getopts ":hHIndDM:CRXUVqL:KBZc:FS:" opt
do
case $opt in
S)
Expand Down Expand Up @@ -79,8 +79,21 @@ do
n)
GSH_COLOR=""
;;
P)
GSH_MODE="PASSPORT"
M)
case "$OPTARG" in
passport)
GSH_MODE="PASSPORT"
;;
anonymous)
GSH_MODE="ANONYMOUS"
;;
debug)
GSH_MODE="debug"
;;
*)
echo "$(eval_gettext "Error: invalid mode (option -M): '-\$OPTARG'")" >&2
exit 1
esac
;;
d)
GSH_MODE="DEBUG"
Expand All @@ -92,9 +105,6 @@ do
q)
export GSH_QUIET_INTRO="true"
;;
A)
GSH_MODE="ANONYMOUS"
;;
C)
RESET="FALSE"
;;
Expand Down
23 changes: 17 additions & 6 deletions utils/archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ options:
-h this message
-p ... choose password for admin commands
-P use the "passport mode" by default when running GameShell
-A use the "anonymous mode" by default when running GameShell
-M passport use the "passport mode" by default when running GameShell
-M anonymous use the "anonymous mode" by default when running GameShell
-L LANGS only keep the given languages (ex: -L 'en*,fr')
if LANGS is empty (-L ""), only keep english as a language,
not generating any ".mo" file and not using gettext
Expand Down Expand Up @@ -67,7 +67,7 @@ VERBOSE=""

INDEX_FILES=""

while getopts "hp:N:atPzL:vS:p:I:" opt
while getopts "hp:N:atM:zL:vS:p:I:" opt
do
case $opt in
h)
Expand All @@ -94,7 +94,7 @@ do
I)
if [ "$OPTARG" = "default.idx" ]
then
echo "Warning: ignoring additional index file with name '$OPTARG'"
echo "Warning: ignoring additional index file with name '$OPTARG'" >&2
else
INDEX_FILES="$INDEX_FILES:$OPTARG"
fi
Expand All @@ -105,8 +105,19 @@ do
t)
KEEP_TEST=1
;;
P)
DEFAULT_MODE="PASSPORT"
M)
case "$OPTARG" in
passport)
DEFAULT_MODE="PASSPORT"
;;
anonymous)
DEFAULT_MODE="ANONYMOUS"
;;
*)
echo "Error: default mode (option -M) can only be 'anonymous' or 'passport' (got '$OPTARG')" >&2
exit 1
;;
esac
;;
z)
KEEP_TGZ=1
Expand Down

0 comments on commit 0a90c74

Please sign in to comment.