Skip to content

Commit

Permalink
move out Parse command line arguments from func
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnaf-tahmid-chowdhury committed Aug 31, 2023
1 parent 042a739 commit a15f972
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions install-nuclear-boy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a15f972

Please sign in to comment.