From a15f9726f3f168802ff868c69f42146eec5d96fa Mon Sep 17 00:00:00 2001 From: Ahnaf Tahmid Chowdhury Date: Thu, 31 Aug 2023 17:02:57 +0600 Subject: [PATCH] move out Parse command line arguments from func --- install-nuclear-boy.sh | 54 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/install-nuclear-boy.sh b/install-nuclear-boy.sh index 66be27f..f4d947d 100755 --- a/install-nuclear-boy.sh +++ b/install-nuclear-boy.sh @@ -6,6 +6,32 @@ set -e # Set the version Version="0.1.0" +# Parse command line arguments + while getopts ":d:e:g:c:" opt; do + case $opt in + d) + install_dir="$OPTARG" + ;; + e) + env_name="$OPTARG" + ;; + g) + geant4_data_lib="$OPTARG" + ;; + c) + cross_section_data_lib="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac + done + detect_os() { if [[ (-z "${os}") && (-z "${dist}") ]]; then # some systems dont have lsb-release yet have the lsb_release binary and @@ -72,33 +98,6 @@ detect_version_id() { echo "Detected version id as $version" } -parse_command_line_arguments() { - while getopts ":d:e:g:c:" opt; do - case $opt in - d) - install_dir="$OPTARG" - ;; - e) - env_name="$OPTARG" - ;; - g) - geant4_data_lib="$OPTARG" - ;; - c) - cross_section_data_lib="$OPTARG" - ;; - \?) - echo "Invalid option: -$OPTARG" >&2 - exit 1 - ;; - :) - echo "Option -$OPTARG requires an argument." >&2 - exit 1 - ;; - esac - done -} - set_install_directory() { if [ -z "$install_dir" ]; then working_dir="$(cd -P "$(dirname -- "${BASH_SOURCE}")" >/dev/null 2>&1 && pwd)" @@ -1065,7 +1064,6 @@ main() { echo "Welcome to the NuclearBoy installer!" echo "This package manager will install the PyNE, OpenMC, DAGMC and Geant4 on your system." echo - parse_command_line_arguments set_install_directory set_env_name set_geant4_data_lib