Skip to content

Commit

Permalink
src/winusb: Move print_help and process_commandline_parameters functi…
Browse files Browse the repository at this point in the history
…on to right after init

Signed-off-by: 林博仁 <[email protected]>
  • Loading branch information
brlin-tw committed Jun 7, 2017
1 parent a955762 commit 5b390d0
Showing 1 changed file with 111 additions and 111 deletions.
222 changes: 111 additions & 111 deletions src/winusb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,117 @@ init(){
exit 0
}; declare -fr init

print_help(){
util_check_function_parameters_quantity 0 "${#}"

set +o xtrace
echo -e "${APPLICATION_NAME}'s Help"
echo -e "=========================="
echo -e "Create a bootable Windows USB device from a bootable Windows optical disk or an disk image"
echo -e
echo -e "Copy Windows files to an existing FAT partition of an USB storage and make it bootable"
echo -e "NOTE: All files that has the same name will be OVERWRITTEN!"
echo -e "\t""${RUNTIME_EXECUTABLE_NAME} --install <source media path> <partition>"
echo -e "\t""Example: ${RUNTIME_EXECUTABLE_NAME} --install win7_amd64.iso /dev/sdX1"
echo -e "\t""Example: ${RUNTIME_EXECUTABLE_NAME} --install /dev/sr0 /dev/sdX1"
echo -e
echo -e "Completely DESTROY all previous data on an USB storage, copy Windows files and make it bootable"
echo -e "\t""${RUNTIME_EXECUTABLE_NAME} --format <source media path> <device>"
echo -e "\t""Example: ${RUNTIME_EXECUTABLE_NAME} --format win7_amd64.iso /dev/sdX"
echo -e "\t""Example: ${RUNTIME_EXECUTABLE_NAME} --format /dev/sr0 /dev/sdX"
echo -e
echo -e "Options"
echo -e "\t--verbose, -v ""Verbose mode"
echo -e "\t--help, -h ""Show this help message and exit"
echo -e "\t--no-color ""Disable color"
echo -e "\t--debug, -d ""Enable script debugging"
}; declare -fr print_help

process_commandline_parameters(){
util_check_function_parameters_quantity 3 "${#}"
local -n install_mode_ref="${1}"; shift
local -n source_media_ref="${1}"; shift
local -n target_media_ref="${1}"

if [ "${#RUNTIME_COMMANDLINE_PARAMETERS[@]}" -eq 0 ]; then
print_help
exit 0
fi

local -a parameters=("${RUNTIME_COMMANDLINE_PARAMETERS[@]}")
local enable_debug=N

while [ "${#parameters[@]}" -ne 0 ]; do
case "${parameters[0]}" in
"--help"\
|"-h")
print_help;
exit 0
;;
"--debug"\
|"-d")
enable_debug="Y"
;;
'--install')
install_mode_ref='partition'
shift_array parameters
if [ "${#parameters[@]}" -lt 2 ]; then
echo_with_color\
"red"\
"${FUNCNAME[0]}: Error: --install option requires 2 arguments!"
return 1
fi
source_media_ref="${parameters[0]}"
shift_array parameters
target_media_ref="${parameters[0]}"
;;
'--format')
# Limitation of ShellCheck to detect usage of indirection variables
# https://github.com/koalaman/shellcheck/wiki/SC2034
# shellcheck disable=SC2034
install_mode_ref='device'
shift_array parameters
if [ "${#parameters[@]}" -lt 2 ]; then
echo_with_color\
"red"\
"${FUNCNAME[0]}: Error: --format option requires 2 arguments!"
return 1
fi
source_media_ref="${parameters[0]}"
shift_array parameters
target_media_ref="${parameters[0]}"
;;
'--verbose'|'-v')
verbose='1'
;;
'--for-gui')
no_color='1'
only_for_gui='1'
;;
'--no-color')
no_color='1'
;;
*)
echo_with_color red "ERROR: Unknown command-line argument \"${parameters[0]}\"" >&2
return 1
;;
esac
shift_array parameters
done

if [ "${verbose}" = "1" ] && [ "${enable_debug}" != "Y" ]; then
trap 'trap_return "${FUNCNAME[0]}"' RETURN

# Disabled due to FIXME
# trap 'trap_debug "${BASH_COMMAND}"' DEBUG
fi

if [ "${enable_debug}" = "Y" ]; then
set -o xtrace
fi
return 0
}; declare -fr process_commandline_parameters;

check_target_filesystem_free_space(){
util_check_function_parameters_quantity 2 $#
local -r target_fs_mountpoint="${1}"; shift
Expand Down Expand Up @@ -805,117 +916,6 @@ copy_filesystem_files(){
return 0
}; declare -fr copy_filesystem_files

print_help(){
util_check_function_parameters_quantity 0 "${#}"

set +o xtrace
echo -e "${APPLICATION_NAME}'s Help"
echo -e "=========================="
echo -e "Create a bootable Windows USB device from a bootable Windows optical disk or an disk image"
echo -e
echo -e "Copy Windows files to an existing FAT partition of an USB storage and make it bootable"
echo -e "NOTE: All files that has the same name will be OVERWRITTEN!"
echo -e "\t""${RUNTIME_EXECUTABLE_NAME} --install <source media path> <partition>"
echo -e "\t""Example: ${RUNTIME_EXECUTABLE_NAME} --install win7_amd64.iso /dev/sdX1"
echo -e "\t""Example: ${RUNTIME_EXECUTABLE_NAME} --install /dev/sr0 /dev/sdX1"
echo -e
echo -e "Completely DESTROY all previous data on an USB storage, copy Windows files and make it bootable"
echo -e "\t""${RUNTIME_EXECUTABLE_NAME} --format <source media path> <device>"
echo -e "\t""Example: ${RUNTIME_EXECUTABLE_NAME} --format win7_amd64.iso /dev/sdX"
echo -e "\t""Example: ${RUNTIME_EXECUTABLE_NAME} --format /dev/sr0 /dev/sdX"
echo -e
echo -e "Options"
echo -e "\t--verbose, -v ""Verbose mode"
echo -e "\t--help, -h ""Show this help message and exit"
echo -e "\t--no-color ""Disable color"
echo -e "\t--debug, -d ""Enable script debugging"
}; declare -fr print_help

process_commandline_parameters(){
util_check_function_parameters_quantity 3 "${#}"
local -n install_mode_ref="${1}"; shift
local -n source_media_ref="${1}"; shift
local -n target_media_ref="${1}"

if [ "${#RUNTIME_COMMANDLINE_PARAMETERS[@]}" -eq 0 ]; then
print_help
exit 0
fi

local -a parameters=("${RUNTIME_COMMANDLINE_PARAMETERS[@]}")
local enable_debug=N

while [ "${#parameters[@]}" -ne 0 ]; do
case "${parameters[0]}" in
"--help"\
|"-h")
print_help;
exit 0
;;
"--debug"\
|"-d")
enable_debug="Y"
;;
'--install')
install_mode_ref='partition'
shift_array parameters
if [ "${#parameters[@]}" -lt 2 ]; then
echo_with_color\
"red"\
"${FUNCNAME[0]}: Error: --install option requires 2 arguments!"
return 1
fi
source_media_ref="${parameters[0]}"
shift_array parameters
target_media_ref="${parameters[0]}"
;;
'--format')
# Limitation of ShellCheck to detect usage of indirection variables
# https://github.com/koalaman/shellcheck/wiki/SC2034
# shellcheck disable=SC2034
install_mode_ref='device'
shift_array parameters
if [ "${#parameters[@]}" -lt 2 ]; then
echo_with_color\
"red"\
"${FUNCNAME[0]}: Error: --format option requires 2 arguments!"
return 1
fi
source_media_ref="${parameters[0]}"
shift_array parameters
target_media_ref="${parameters[0]}"
;;
'--verbose'|'-v')
verbose='1'
;;
'--for-gui')
no_color='1'
only_for_gui='1'
;;
'--no-color')
no_color='1'
;;
*)
echo_with_color red "ERROR: Unknown command-line argument \"${parameters[0]}\"" >&2
return 1
;;
esac
shift_array parameters
done

if [ "${verbose}" = "1" ] && [ "${enable_debug}" != "Y" ]; then
trap 'trap_return "${FUNCNAME[0]}"' RETURN

# Disabled due to FIXME
# trap 'trap_debug "${BASH_COMMAND}"' DEBUG
fi

if [ "${enable_debug}" = "Y" ]; then
set -o xtrace
fi
return 0
}; declare -fr process_commandline_parameters;

shift_array(){
util_check_function_parameters_quantity 1 "${#}"

Expand Down

0 comments on commit 5b390d0

Please sign in to comment.