Skip to content

Commit

Permalink
Ubuntu: Refactor CLI parameter handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-revay authored Dec 26, 2024
1 parent 1cb27b3 commit 112d1d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
11 changes: 4 additions & 7 deletions UbuntuCLI/interactive_part.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ function interactive_part

# TODO improve parameter parsing - move it to platform-independent code

if [ "$1" == "--noninteractive" ]; then
echo "Skipping interactive commands as $1 parameter was provided"
elif [ "$1" == "" ]; then
interactive_part
if [ "${NONINTERACTIVE}" == 'true' ]; then
echo 'Skipping interactive commands as --noninteractive parameter was provided'
else
echo "invalid argument $1"
exit "${EXIT_INVALID_ARGUMENT}"
fi
interactive_part
fi
11 changes: 1 addition & 10 deletions UbuntuCLI/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@ distro_is ubuntu
distro_version_ge 22
gnome_present no

# TODO improve parameter parsing - move it to platform-independent code
if [ "$1" = "--help" ]; then
echo "usage: ./run_all.sh [--noninteractive]"
echo
# shellcheck disable=SC2016
echo '--noninteractive skip stuff requiring user interaction (e.g. `gh auth login`)'
exit "${EXIT_SUCCESS}"
fi

# Run stuff that requires user input first (if not turned off by `--noninteractive`)
. ubuntu_specific_packages.sh
. packages_install.sh
# stuff that requires user input can be turned off by `--noninteractive` CLI param
. interactive_part.sh
. optional_packages_install.sh
. configs_install.sh
10 changes: 0 additions & 10 deletions Ubuntu_22.04/interactive_part.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,4 @@
. ../prelude.sh

. ../UbuntuCLI/interactive_part.sh

# TODO racionalize parameter handling (`--help` and invalid parameters are handled in UbuntuCLI)
# TODO -- refactor parameter handling and initialization of the NONINTERACTIVE global variable
if [ "$1" == "--noninteractive" ]; then
readonly NONINTERACTIVE='true'
echo "Ubuntu 22.04 - Skipping interactive commands as $1 parameter was provided"
elif [ "$1" == "" ]; then
echo "Ubuntu 22.04 - Executing the interactive part..."
fi

. ../CommonInitScripts/gnome_install_extensions.sh
17 changes: 17 additions & 0 deletions run_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@

. prelude.sh

# TODO improve parameter parsing - move it to platform-independent code
if [ "$1" = "--help" ]; then
echo "usage: ./run_all.sh [--noninteractive]"
echo
# shellcheck disable=SC2016
echo '--noninteractive skip stuff requiring user interaction (e.g. `gh auth login`)'
exit "${EXIT_SUCCESS}"
elif [ "$1" == "--noninteractive" ]; then
readonly NONINTERACTIVE='true'
echo 'NONINTERACTIVE=true'
elif [ "$1" == "" ]; then
echo "Interactive part of the script will be executed at the end..."
else
echo "Invalid argument $1"
exit "${EXIT_INVALID_ARGUMENT}"
fi

LOG_PATH="$(pwd)/Logs/$(date '+%Y%m%d_%H%M%S').log"
readonly LOG_PATH
mkdir -p "$(dirname "${LOG_PATH}")"
Expand Down

0 comments on commit 112d1d7

Please sign in to comment.