Skip to content

Commit

Permalink
feat: Add the --force argument to arch-update --gen-config to all…
Browse files Browse the repository at this point in the history
…ow overwriting any existing `arch-update.conf` (#251)

Add support for the `--force` argument with `arch-update --gen-config` to allow overwriting any existing `arch-update.conf` configuration file:
`arch-update --gen-config --force`
  • Loading branch information
Antiz96 authored Sep 25, 2024
1 parent b6c5eca commit 8e136c0
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README-fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Options :
-d, --devel Inclure les mises à jour des paquets de développement AUR
-n, --news [Num] Afficher les dernieres Arch News, vous pouvez optionellement spécifier le nombre de Arch news à afficher avec `--news [Num]` (e.g. `--news 10`)
-D, --debug Afficher les traces de débogage
--gen-config Générer un fichier de configuration `arch-update.conf` par défaut/exemple (voir la page de manuel arch-update.conf(5) pour plus de détails)
--gen-config Générer un fichier de configuration `arch-update.conf` par défaut/exemple (voir la page de manuel arch-update.conf(5) pour plus de détails), vous pouvez optionnellement passer l'argument `--force` pour écraser un fichier de configuration `arch-update.conf` existant
--show-config Afficher le fichier de configuration `arch-update.conf` actuellement utilisé (s'il existe)
--edit-config Editer le fichier de configuration `arch-update.conf` actuellement utilisé (s'il existe)
--tray Lancer l'applet systray d'Arch-Update, vous pouvez optionnellement ajouter l'argument `--enable` pour la démarrer automatiquement au démarrage du système.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Options:
-d, --devel Include AUR development packages updates
-n, --news [Num] Display latest Arch News, you can optionally specify the number of Arch news to display with `--news [Num]` (e.g. `--news 10`)
-D, --debug Display debug traces
--gen-config Generate a default/example `arch-update.conf` configuration file (see the arch-update.conf(5) man page for more details)
--gen-config Generate a default/example `arch-update.conf` configuration file (see the arch-update.conf(5) man page for more details), you can optionally pass the `--force` argument to overwrite any existing `arch-update.conf` configuration file
--show-config Display the `arch-update.conf` configuration file currently used (if it exists)
--edit-config Edit the `arch-update.conf` configuration file currently used (if it exists)
--tray Launch the Arch-Update systray applet, you can optionally add the `--enable` argument to start it automatically at boot.
Expand Down
2 changes: 2 additions & 0 deletions doc/man/arch-update.1
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Display debug traces.
.TP
.B \-\-gen\-config
.RB "Generate a default/example " "arch-update.conf " "configuration file (see the " "arch-update.conf(5) " "man page for more details)."
.br
.RB "You can optionally pass the " "--force " "argument to overwrite any existing " "arch-update.conf " "configuration file."

.TP
.B \-\-show\-config
Expand Down
2 changes: 2 additions & 0 deletions doc/man/fr/arch-update.1
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Afficher les traces de débogage.
.TP
.B \-\-gen\-config
.RB "Générer un fichier de configuration " "arch-update.conf " "par défaut/exemple (voir la page de manuel " "arch-update.conf(5) " "pour plus de détails)."
.br
.RB "Vous pouvez optionnellement passer l'argument " "--force " "pour écraser un fichier de configuration " "arch-update.conf " "existant."

.TP
.B \-\-show\-config
Expand Down
5 changes: 3 additions & 2 deletions po/arch-update.pot
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ msgstr ""
#, sh-format
msgid ""
"The '${config_file}' configuration file already exists\\nPlease, remove it "
"before generating a new one"
"before generating a new one (or use --force to overwrite it)"
msgstr ""

#: src/lib/gen-config.sh:30
Expand Down Expand Up @@ -176,7 +176,8 @@ msgstr ""
#, sh-format
msgid ""
" --gen-config Generate a default/example 'arch-update.conf' "
"configuration file"
"configuration file, you can optionally pass the '--force' argument to "
"overwrite any existing 'arch-update.conf' configuration file"
msgstr ""

#: src/lib/help.sh:22
Expand Down
12 changes: 7 additions & 5 deletions po/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ msgstr "Fichier de configuration exemple non trouvé"
#, sh-format
msgid ""
"The '${config_file}' configuration file already exists\\nPlease, remove it "
"before generating a new one"
"before generating a new one (or use --force to overwrite it)"
msgstr ""
"Le fichier de configuration '${config_file}' existe déjà.\\nVeuillez le supprimer "
"avant d'en générer un nouveau"
"Le fichier de configuration '${config_file}' existe déjà\\nVeuillez le supprimer "
"avant d'en générer un nouveau (ou utilisez --force pour l'écraser)"

#: src/lib/gen-config.sh:30
#, sh-format
Expand Down Expand Up @@ -202,10 +202,12 @@ msgstr " -D, --debug Afficher les traces de débogage"
#, sh-format
msgid ""
" --gen-config Generate a default/example 'arch-update.conf' "
"configuration file"
"configuration file, you can optionally pass the '--force' argument to "
"overwrite any existing 'arch-update.conf' configuration file"
msgstr ""
" --gen-config Générer un fichier de configuration 'arch-update.conf' "
"par défaut/exemple"
"par défaut/exemple, vous pouvez optionnellement passer l'argument '--force' pour "
"écraser un fichier de configuration 'arch-update.conf' existant"

#: src/lib/help.sh:22
#, sh-format
Expand Down
5 changes: 5 additions & 0 deletions src/arch-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ case "${option}" in
source "${libdir}/list_news.sh"
;;
--gen-config)
# Check if the user specified to overwrite any existing "arch-update.conf" configuration file
if [ "${2}" == "--force" ]; then
overwrite_config_file="true"
fi

# Source the "gen-config" library which generates a default "arch-update.conf" configuration file (if it doesn't exists yet)
# shellcheck source=src/lib/gen-config.sh
source "${libdir}/gen-config.sh"
Expand Down
6 changes: 3 additions & 3 deletions src/lib/gen-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ else
fi

# shellcheck disable=SC2154
if [ -f "${config_file}" ]; then
error_msg "$(eval_gettext "The '\${config_file}' configuration file already exists\nPlease, remove it before generating a new one")"
if [ -f "${config_file}" ] && [ -z "${overwrite_config_file}" ]; then
error_msg "$(eval_gettext "The '\${config_file}' configuration file already exists\nPlease, remove it before generating a new one (or use --force to overwrite it)")"
exit 8
else
mkdir -p "${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/"
cp "${example_config_file}" "${config_file}" || exit 8
cp -f "${example_config_file}" "${config_file}" || exit 8
info_msg "$(eval_gettext "The '\${config_file}' configuration file has been generated")"
fi
2 changes: 1 addition & 1 deletion src/lib/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $(eval_gettext " -l, --list Display the list of pending updates")
$(eval_gettext " -d, --devel Include AUR development packages updates")
$(eval_gettext " -n, --news [Num] Display latest Arch news, you can optionally specify the number of Arch news to display with '--news [Num]' (e.g. '--news 10')")
$(eval_gettext " -D, --debug Display debug traces")
$(eval_gettext " --gen-config Generate a default/example 'arch-update.conf' configuration file")
$(eval_gettext " --gen-config Generate a default/example 'arch-update.conf' configuration file, you can optionally pass the '--force' argument to overwrite any existing 'arch-update.conf' configuration file")
$(eval_gettext " --show-config Display the 'arch-update.conf' configuration file currently used (if it exists)")
$(eval_gettext " --edit-config Edit the 'arch-update.conf' configuration file currently used (if it exists)")
$(eval_gettext " --tray Launch the Arch-Update systray applet, you can optionally add the '--enable' argument to start it automatically at boot")
Expand Down

0 comments on commit 8e136c0

Please sign in to comment.