Skip to content

Commit

Permalink
fix removing trailing semicolon logic in bat (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas authored Dec 10, 2019
1 parent 8a06f55 commit e1a1029
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions colcon_core/shell/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class BatShell(ShellExtensionPoint):
FORMAT_STR_USE_ENV_VAR = '%{name}%'
FORMAT_STR_INVOKE_SCRIPT = 'call:_colcon_prefix_bat_call_script ' \
'"{script_path}"'
FORMAT_STR_REMOVE_TRAILING_SEPARATOR = 'if "%{name}:~-1%==";" ' \
'set {name}=%{name}:~0,-1%'
# can't use `if` here since each line is being `call`-ed
FORMAT_STR_REMOVE_TRAILING_SEPARATOR = \
'call:_colcon_prefix_bat_strip_trailing_semicolon "{name}"'

def __init__(self): # noqa: D107
super().__init__()
Expand Down
14 changes: 14 additions & 0 deletions colcon_core/shell/template/prefix.bat.em
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,17 @@ goto:eof
echo not found: "%~1" 1>&2
)
goto:eof


:: strip a trailing semicolon from an environment variable if applicable
:: first argument: the environment variable name
:_colcon_prefix_bat_strip_trailing_semicolon
setlocal enabledelayedexpansion
set "name=%~1"
set "value=!%name%!"
if "%value:~-1%"==";" set "value=%value:~0,-1%"
:: set result variable in parent scope
endlocal & (
set "%~1=%value%"
)
goto:eof

0 comments on commit e1a1029

Please sign in to comment.