84 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/sh
 | |
| 
 | |
| # ybcon start script
 | |
| 
 | |
| EXENAME=ybcon
 | |
| 
 | |
| scriptDir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
 | |
| 
 | |
| # Location of the executable
 | |
| defaultBinLocation="$scriptDir/../libexec/ybcon"
 | |
| 
 | |
| usage() {
 | |
|   if [ "$1" = false ]; then echo "Invalid arguments, usage:"; fi
 | |
|   echo "$EXENAME [--version] [-h|--help] [--parallel] [--target=<target>] [-p|--printresult] <file>"
 | |
|   if [ "$1" = true ]; then
 | |
|     echo "        --version Print the version"
 | |
|     echo "        -h or --help What you're seeing right now"
 | |
|     echo "        --parallel Transpile files in parallel mode"
 | |
|     echo "        --target=<target> Set the transpilation target"
 | |
|     echo "        -p or --printresult Enable printing the transpilation result to stdout"
 | |
|     printf "\n"
 | |
|   fi
 | |
| }
 | |
| 
 | |
| usageExit() {
 | |
|   usage false
 | |
|   exit 0
 | |
| }; helpExit() { usage true; exit 0; }
 | |
| 
 | |
| args="";
 | |
| run=false;
 | |
| 
 | |
| newArgs() {
 | |
|   if [ "$args" = "" ]; then
 | |
|     args="$args$1"
 | |
|   else
 | |
|     args="$args $1"
 | |
|   fi
 | |
| }
 | |
| 
 | |
| if [ "$#" != 0 ]; then
 | |
|   if [ "$#" = 1 ]; then
 | |
|     case "$1" in
 | |
|       -h | --help )
 | |
|         helpExit ;;
 | |
|       --version )
 | |
|         run=true; args="$1" ;;
 | |
|       *.ybcon )
 | |
|         newArgs "$1"; run=true ;;
 | |
|       * )
 | |
|         usageExit ;;
 | |
|     esac
 | |
|   else
 | |
|     for it in "$@"
 | |
|       do
 | |
|         case "$it" in
 | |
|           -p | --printresult | --parallel | --target=* )
 | |
|             if test "${args#*$it}" = "$args"; then
 | |
|               newArgs "$it"
 | |
|             else
 | |
|               usageExit
 | |
|             fi ;;
 | |
|           *.ybcon )
 | |
|             newArgs "$it"
 | |
|             run=true ;;
 | |
|           * )
 | |
|             usageExit ;;
 | |
|         esac
 | |
|       done
 | |
|     if test "${args#*".ybcon"}" = "$args" ; then usageExit; fi
 | |
|   fi
 | |
| else
 | |
|   usage false
 | |
| fi
 | |
| 
 | |
| runIt() { eval "$1" " $args"; }
 | |
| 
 | |
| if [ "$run" = true ]; then
 | |
|   if [ -f "$defaultBinLocation" ]; then
 | |
|     runIt "$defaultBinLocation"
 | |
|   else
 | |
|     echo "Yerbacon executable not found at $defaultBinLocation"
 | |
|   fi
 | |
| fi |