Last active
September 18, 2023 03:16
-
-
Save Danendra10/2910ae7a55e066aa03fec7c967e00b71 to your computer and use it in GitHub Desktop.
Script to build golang with param of -o [operating_sys] -n [output_name]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#how to use | |
# cd ~ && mkdir gobuildscript && cd gobuildscript && https://gist.github.com/Danendra10/2910ae7a55e066aa03fec7c967e00b71 && chmod +x gobuild.sh && echo "alias gobuild="~/gobuildscript/gpbuild.sh" >> ~/.bashrc && source ~/.bashrc | |
output_name="main" | |
os="linux" | |
# Define colors | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[0;33m' | |
NC='\033[0m' # No Color | |
if [[ $1 == "--help" || $1 == "-h" ]]; then | |
echo -e "${GREEN}Usage:${NC} ./script.sh ${YELLOW}-o [operating_system]${NC} ${YELLOW}-n [output_name]${NC}" | |
echo "" | |
echo -e "${GREEN}PARAMETERS:" | |
echo -e "${YELLOW}-o:${NC} OS" | |
echo -e "${YELLOW}-n:${NC} output name" | |
echo "" | |
exit 0 | |
fi | |
while getopts ":o:n:" opt; do | |
case ${opt} in | |
o ) | |
os=$OPTARG | |
;; | |
n ) | |
output_name=$OPTARG | |
;; | |
\? ) | |
echo "Invalid option: $OPTARG" 1>&2 | |
exit 1 | |
;; | |
: ) | |
echo "Invalid option: $OPTARG requires an argument" 1>&2 | |
exit 1 | |
;; | |
esac | |
done | |
echo "Building for OS: $os" | |
echo "Output name: $output_name" | |
GOOS = $os | |
echo "BUILDING ${output_name}" | |
go build -o ${output_name} main.go | |
echo "BUILD DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment