Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to get help about script usage. #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions scripts/_RosTeamWs_Defines.bash
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,77 @@ function print_and_exit {

message=$1
echo ""
echo -e "${RTW_COLOR_ERROR}$message!!! Exiting...${TERMINAL_COLOR_NC}"
echo -e "${RTW_COLOR_ERROR}$message${TERMINAL_COLOR_NC}"
if [ ! -z "$2" ]; then
echo ""
echo -e "${TERMINAL_COLOR_USER_NOTICE}Usage: '$2'${TERMINAL_COLOR_NC}"
fi
echo -e "${TERMINAL_COLOR_USER_CONFIRMATION}Error has happened. Press <CTRL> + C two times...${TERMINAL_COLOR_NC}"
read -p ""
exit 1
return 2>/dev/null || exit 1
}

function print_error {
RosTeamWS_setup_exports

message=$1
if [ -n "$message" ]; then
echo ""
echo "${TERMINAL_COLOR_RED}ERROR: ${message}${RAW_TERMINAL_COLOR_NC}"
fi
}

function print_warning {
RosTeamWS_setup_exports

message=$1
if [ -n "$message" ]; then
echo ""
echo "${TERMINAL_COLOR_YELLOW}WARNING: ${message}${RAW_TERMINAL_COLOR_NC}"
fi
}

function print_info {
RosTeamWS_setup_exports

message=$1
if [ -n "$message" ]; then
echo ""
echo "INFO: ${message}"
fi
}

function print_notifycation {
RosTeamWS_setup_exports

message=$1
if [ -n "$message" ]; then
echo ""
echo "${TERMINAL_COLOR_BLUE}NOTE: ${message}${TERMINAL_COLOR_NC}"
fi
}

function print_success {
RosTeamWS_setup_exports

message=$1
if [ -n "$message" ]; then
echo ""
echo "${TERMINAL_COLOR_GREEN}SUCCESS: ${message}${TERMINAL_COLOR_NC}"
fi
}

function print_usage {
RosTeamWS_setup_exports

usage=$1
message=$2
if [ -n "$usage" ]; then
print_notifycation "$usage"
fi
if [ -n "$message" ]; then
print_info "$message"
fi
}

function framework_default_paths {
Expand Down
16 changes: 15 additions & 1 deletion scripts/environment/setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ if [[ $ros_version == 1 ]]; then
print_and_exit "'$WS_FOLDER_1' does not exist. Can not find ROS workspace!"
fi

# TODO(destogl): update this as below and put into a function
export ROS_WS=$WS_FOLDER
FILE_TO_SOURCE="$WS_FOLDER/.ros_team_ws_workspace_rc"
if [ -f "$FILE_TO_SOURCE" ]; then
echo -e "${TERMINAL_COLOR_GRAY}Sourcing custom environment variables for the workspace from file: '$FILE_TO_SOURCE'${TERMINAL_COLOR_NC}"
source "$FILE_TO_SOURCE"
fi

export ROS_WS=$WS_FOLDER
source "$WS_FOLDER/devel/setup.bash"

echo ""
echo "RosTeamWS: Sourced file: $WS_FOLDER/devel/setup.bash"
echo -e "${TERMINAL_COLOR_BLUE}RosTeamWS: Sourced file: $WS_FOLDER/devel/setup.bash${TERMINAL_COLOR_NC}"


elif [[ $ros_version == 2 ]]; then
Expand Down Expand Up @@ -110,6 +118,12 @@ elif [[ $ros_version == 2 ]]; then
fi

export ROS_WS=$WS_FOLDER
FILE_TO_SOURCE="$WS_FOLDER/.ros_team_ws_workspace_rc"
if [ -f "$FILE_TO_SOURCE" ]; then
echo -e "${TERMINAL_COLOR_LIGHT_BLUE} sourcing custom environment variables for the workspace from file: '$FILE_TO_SOURCE'."
source "$FILE_TO_SOURCE"
fi

# TODO: COLCON_WS is deprecated!!
export COLCON_WS=$ROS_WS
FILE_TO_SOURCE="$WS_FOLDER/install/setup.bash"
Expand Down
10 changes: 10 additions & 0 deletions scripts/setup-ros-workspace.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ setup_ws_script_own_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null &&
source $setup_ws_script_own_dir/_RosTeamWs_Defines.bash
source $setup_ws_script_own_dir/docker/_RosTeamWs_Docker_Defines.bash


# TODO(destogl): can we somehow reuse this in each and every script: a function? or source?
if [ -z "$1" ]; then
print_and_exit "No input parameters provided" "$usage"
return 2>/dev/null || exit
elif [[ $1 == "--help" || $1 == "-h" ]]; then
print_and_exit "Here is the usage help for this script:" "$usage"
return 2>/dev/null || exit
fi

check_user_input () {
# ros distribution name will be set in ${ros_distro}
check_ros_distro "$1"
Expand Down