You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to try your compiler on the script generated by my tool parseArger but unfortunatly, I get this error when trying to build : Error: syntax error: expected ]to close conditional expression, found-. (line: 8, column: 39)
The command I use to build : docker run -v .:/bunster ghcr.io/yassinebenaid/bunster:latest bunster build hello-world.sh -o hi
and the bash script I try to compile
#!/bin/bash# @parseArger-begin# @parseArger-help "Hi" --option "help" --short-option "h"# @parseArger-verbose --option "verbose" --level "0" --quiet-option "quiet"
_has_colors=0
if [ -t 1 ];then# Check if stdout is a terminal
ncolors=$(tput colors 2>/dev/null)if [ -n"$ncolors" ] && [ "$ncolors"-ge 8 ];then
_has_colors=1
fifi# @parseArger-declarations# @parseArger pos person "who to greet"# @parseArger opt greet "how to greet" --default-value "Hello"# @parseArger flag exclam "!"# @parseArger-declarations-end# @parseArger-utils
_helpHasBeenPrinted=1;
_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"&&pwd -P)";# @parseArger-utils-end# @parseArger-parsing
__cli_arg_count=$#;die()
{
local _ret=1
if [[ -n"$2" ]] && [[ "$2"=~ ^[0-9]+$ ]];then
_ret="$2"fitest"${_PRINT_HELP:-no}" = yes && print_help >&2
log "$1" -3 >&2exit"${_ret}"
}
begins_with_short_option()
{
local first_option all_short_options=''
first_option="${1:0:1}"test"$all_short_options" = "${all_short_options/$first_option/}"&&return 1 ||return 0
}
# POSITIONALS ARGUMENTS
_positionals=();
_optional_positionals=();
_arg_person="";# OPTIONALS ARGUMENTS
_arg_greet="Hello"# FLAGS
_arg_exclam="off"# NESTED
_verbose_level="0";print_help()
{
_triggerSCHelp=1;if [[ "$_helpHasBeenPrinted"=="1" ]];then
_helpHasBeenPrinted=0;echo -e "Hi:"echo -e " person: who to greet"echo -e " --greet <greet>: how to greet [default: ' Hello ']"echo -e " --exclam|--no-exclam: !"echo -e "Usage :$0 <person> [--greet <value>] [--[no-]exclam]";fi
}
log() {
local _arg_msg="${1}";local _arg_level="${2:-0}";if [ "${_arg_level}"-le"${_verbose_level}" ];thencase"$_arg_level"in
-3)
_arg_COLOR="�[0;31m";
;;
-2)
_arg_COLOR="�[0;33m";
;;
-1)
_arg_COLOR="�[1;33m";
;;
1)
_arg_COLOR="�[0;32m";
;;
2)
_arg_COLOR="�[1;36m";
;;
3)
_arg_COLOR="�[0;36m";
;;
*)
_arg_COLOR="�[0m";
;;
esacif [ "${_has_colors}"=="1" ];thenecho -e "${_arg_COLOR}${_arg_msg}�[0m";elseecho"${_arg_msg}";fifi
}
parse_commandline()
{
_positionals_count=0
whiletest$# -gt 0
do
_key="$1"case"$_key"in
--greet)
test$# -lt 2 && die "Missing value for the option: '$_key'" 1
_arg_greet="$2"shift
;;
--greet=*)
_arg_greet="${_key##--greet=}"
;;
--exclam)
_arg_exclam="on"
;;
--no-exclam)
_arg_exclam="off"
;;
-h|--help)
print_help;exit 0;
;;
-h*)
print_help;exit 0;
;;
--verbose)
if [ $#-lt 2 ];then
_verbose_level="$((_verbose_level +1))";else
_verbose_level="$2";shift;fi
;;
--quiet)
if [ $#-lt 2 ];then
_verbose_level="$((_verbose_level -1))";else
_verbose_level="-$2";shift;fi
;;
*)
_last_positional="$1"
_positionals+=("$_last_positional")
_positionals_count=$((_positionals_count +1))
;;
esacshiftdone
}
handle_passed_args_count()
{
local _required_args_string="person"if [ "${_positionals_count}"-gt 1 ] && [ "$_helpHasBeenPrinted"=="1" ];then
_PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect at most 1 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}').${_positionals[*]}" 1
fiif [ "${_positionals_count}"-lt 1 ] && [ "$_helpHasBeenPrinted"=="1" ];then
_PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require at least 1 (namely: $_required_args_string), but got only ${_positionals_count}.${_positionals[*]}" 1;fi
}
assign_positional_args()
{
local _positional_name _shift_for=$1;
_positional_names="_arg_person ";shift"$_shift_for"for_positional_namein${_positional_names};dotest$# -gt 0 ||break;eval"if [ \"\$_one_of${_positional_name}\" != \"\" ];then [[ \"\${_one_of${_positional_name}[*]}\" =~ \"\${1}\" ]];fi"|| die "${_positional_name} must be one of: $(eval "echo \"\${_one_of${_positional_name}[*]}\"")" 1;eval"$_positional_name=\${1}"|| die "Error during argument parsing, possibly an ParseArger bug." 1;shift;done
}
print_debug()
{
print_help
# shellcheck disable=SC2145echo"DEBUG: $0$@";echo -e " person: ${_arg_person}";echo -e " greet: ${_arg_greet}";echo -e " exclam: ${_arg_exclam}";
}
on_interrupt() {
die Process aborted! 130;
}
parse_commandline "$@";
handle_passed_args_count;
assign_positional_args 1 "${_positionals[@]}";trap on_interrupt INT;# @parseArger-parsing-end# print_debug "$@"# @parseArger-end
output="$_arg_greet, $_arg_person";if [ "$_arg_exclam"=="on" ];then
output+=" !";fiecho"$output"
to try it ./hello-world.sh Yassine --greet "Salam alaykum" --exclam
and if you want to generate the parsing code with parseArger
I wanted to try your compiler on the script generated by my tool parseArger but unfortunatly, I get this error when trying to build :
Error: syntax error: expected
]to close conditional expression, found
-. (line: 8, column: 39)
The command I use to build :
docker run -v .:/bunster ghcr.io/yassinebenaid/bunster:latest bunster build hello-world.sh -o hi
and the bash script I try to compile
to try it
./hello-world.sh Yassine --greet "Salam alaykum" --exclam
and if you want to generate the parsing code with parseArger
I am concious it might be very much an edge case but I like the idea of being able to compile my bash scripts !
Are there pit falls I should avoid for Bunster to work best ?
The text was updated successfully, but these errors were encountered: