Skip to content

Commit

Permalink
升级版本v0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerWordTree committed Dec 26, 2023
1 parent 2615e13 commit df90387
Show file tree
Hide file tree
Showing 24 changed files with 142 additions and 161 deletions.
7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 更新历史

## 0.2.3 / 2023-12-26

- 增加`;`注释符
- 修改 CONFIG 为 MAP 数据结构
- 备份文件与配置文件顺序相同
- 重新整理 Script 脚本调用

## 0.2.0 / 2023-12-24

- 设置工作目录为配置文件所在目录
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

- 注释行(comment)

`#`开头的行.
`#`或者`;`开头的行.

- 无效行(invalid)

不含`=` 或者 值为空.
不含`=` 或者 键值为空.

- 段(section)

Expand Down
12 changes: 6 additions & 6 deletions Script/Config.ArgParser.CMD → Script/Argument.Parser.CMD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
::@author FB
::@version 0.1.0
::@version 0.2.0

::有序参数: 实例.PARAM, 保存为Array
::选项参数: 实例.OPTION, 保存为Map
Expand All @@ -12,19 +12,19 @@
:: 参数1: 实例名称
:: 参数N: 参数

::Script:Array.Clear.CMD::
::Script:Array.New.CMD::
::Script:Array.Push.CMD::
::Script:Map.Clear.CMD::
::Script:Map.New.CMD::
::Script:Map.Put.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET "@VAR=%~1"
CALL Array.Clear.CMD "%@VAR%.PARAM"
CALL Map.Clear.CMD "%@VAR%.OPTION"
CALL Array.New.CMD "%@VAR%.PARAM"
CALL Map.New.CMD "%@VAR%.OPTION"
:_ARG_PARSE_LOOP
SHIFT
IF "%1" == "" (SET "@=" & SET "@VAR=" & EXIT /B)
IF "%1" == "" (SET "@VAR=" & EXIT /B)
SET "@=%~1"
ECHO.%@% | FINDSTR "^[-/]" 1>NUL 2>&1 && (
ECHO.%~2 | FINDSTR /R /C:"^[-/]" /C:"^[ ]*$" 1>NUL 2>&1 && (
Expand Down
14 changes: 0 additions & 14 deletions Script/Array.Clear.CMD

This file was deleted.

3 changes: 3 additions & 0 deletions Script/Array.New.CMD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
::创建
:: 参数1: 实例名称

::Script:Array.Destroy.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CALL Array.Destroy.CMD "%~1"
SET /A "%~1.@ARRAY=0"
EXIT /B
29 changes: 17 additions & 12 deletions Script/Config.FileRead.CMD
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
::@author FB
::@version 0.1.1
::@version 0.2.0

::数据结构为Object
::仅支持一级段
::由%包裹的变量不会被展开
::数据结构为Map
::仅支持一级段, 由%包裹的变量不会被展开

::如果KEY是#开头,什么也不做
::如果KEY是#或;开头,什么也不做
::如果VALUE不为空,保存到变量
::如果KEY被[]包裹,切换当前段

::读取配置文件
:: 参数1: 实例名称
:: 参数2: 配置文件

::Script:Map.New.CMD::
::Script:Map.NewChild.CMD::
::Script:Map.Put.CMD::
::Script:String.Trim.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET "@VAR=%~1" & SET "@SECTION=."
FOR /F "eol=# tokens=1,* usebackq delims==" %%A IN (
`TYPE "%~2" 2^>NUL`
) DO (
SET "@VAR=%~1" & SET "@SECTION="
CALL Map.New.CMD "%~1"
FOR /F "tokens=1,* usebackq delims==" %%A IN (`TYPE "%~2" 2^>NUL`) DO (
SET "@KEY=%%~A" & SET "@VALUE=%%~B"
CALL String.Trim.CMD "%%@KEY%%" & CALL SET "@KEY=%%@%%"
CALL String.Trim.CMD "%%@VALUE%%" & CALL SET "@VALUE=%%@%%"
Expand All @@ -30,9 +31,13 @@ SET "@VALUE=" & SET "@KEY=" & SET "@SECTION=" & SET "@VAR="
EXIT /B

:_PARSE_LINE
IF NOT "%@KEY:~,1%" == "#" IF NOT "%@VALUE%" == "" (
SET "%@VAR%%@SECTION%%@KEY%=%@VALUE%"
IF "%@KEY%" == "" GOTO :EOF
IF "%@KEY:~,1%" == "#" GOTO :EOF
IF "%@KEY:~,1%" == ";" GOTO :EOF
IF NOT "%@VALUE%" == "" (
CALL Map.Put.CMD "%%@VAR%%%%@SECTION%%" "%%@KEY%%" "%%@VALUE%%"
) ELSE IF "%@KEY:~,1%" == "[" IF "%@KEY:~-1%" == "]" (
SET "@SECTION=.%@KEY:~1,-1%."
SET "@SECTION=.%@KEY:~1,-1%"
CALL Map.NewChild.CMD "%%@VAR%%" "%%@KEY:~1,-1%%"
)
GOTO :EOF
17 changes: 8 additions & 9 deletions Script/Config.FileWrite.CMD
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
::@author FB
::@version 0.1.0
::@version 0.2.0

::数据结构为Object
::仅支持一级段
::数据结构为Map
::仅支持一级段, 由%包裹的变量不会被展开

::写入配置文件
:: 参数1: 实例名称
:: 参数2: 配置文件

::Script:Object.List.CMD::
::Script:Object.ListSub.CMD::
::Script:Object.ListAll.CMD::
::Script:Map.Child.CMD::
::Script:Map.List.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

ECHO # This is an autogenerated file. Do not edit this file directly.>"%~2"
CALL Object.List.CMD "%~1" "{0}={1}">>"%~2"
CALL Map.List.CMD "%~1" "{0}={1}">>"%~2"
FOR /F "usebackq delims=" %%A IN (
`CALL Object.ListSub.CMD "%~1" "{0}"`
`CALL Map.Child.CMD "%~1" "{0}"`
) DO (
ECHO.>>"%~2"
CALL ECHO [%%~A]>>"%~2"
CALL Object.ListAll.CMD "%~1.%%~A" "{0}={1}">>"%~2"
CALL Map.List.CMD "%~1.%%~A" "{0}={1}">>"%~2"
)
EXIT /B
6 changes: 3 additions & 3 deletions Script/Environment.Get.CMD
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
::@author FB
::@version 0.1.0

::Powershell设置环境变量获取
::设置环境变量获取
:: 参数1: 环境变量名
:: 参数2: 作用域(MACHINE/USER/PROCESS)
:: 参数2: 作用域(MACHINE/USER)
:: 返回@: 环境变量值

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Expand All @@ -12,7 +12,7 @@
SETLOCAL
SET "@NAME=%~1" & SET "@TARGET=%~2" & SET "@="
FOR /F "usebackq delims=" %%A IN (
`Powershell.EXE -Command "& { $ErrorActionPreference='Ignore'; [Environment]::GetEnvironmentVariable(${Env:@NAME},${Env:@TARGET}) }"`
`Powershell.EXE -Command "& { [Environment]::GetEnvironmentVariable(${Env:@NAME},${Env:@TARGET}) }"`
) DO (
SET "@=%%~A"
)
Expand Down
6 changes: 3 additions & 3 deletions Script/Environment.Set.CMD
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
::@author FB
::@version 0.1.0

::Powershell设置环境变量
::设置环境变量
:: 参数1: 环境变量名
:: 参数2: 环境变量值
:: 参数3: 作用域(MACHINE/USER/PROCESS)
:: 参数3: 作用域(MACHINE/USER)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@ECHO OFF
SETLOCAL
SET "@NAME=%~1" & SET "@VALUE=%~2" & SET "@TARGET=%~3"
Powershell.EXE -Command "& { $ErrorActionPreference='Ignore'; [Environment]::SetEnvironmentVariable(${Env:@NAME},${Env:@VALUE},${Env:@TARGET}); Exit -Not $? }"
Powershell.EXE -Command "& { [Environment]::SetEnvironmentVariable(${Env:@NAME},${Env:@VALUE},${Env:@TARGET}); Exit -Not $? }"
ENDLOCAL
EXIT /B
16 changes: 16 additions & 0 deletions Script/Map.Child.CMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
::@author FB
::@version 0.2.0

::遍历子项
:: 参数1: 实例名称
:: 参数2: 输出格式({0}子项占位符)
:: 输出: 格式化后的多行字符串

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@ECHO OFF
SETLOCAL
SET "@PREFIX=%~1." & SET "@FMT=%~2"
Powershell.EXE -Command "& { Get-Item Env:${Env:@PREFIX}@CHILD -ErrorAction Ignore | ForEach-Object Value | ForEach-Object {$PSItem.Split(';',[StringSplitOptions]::RemoveEmptyEntries)} | ForEach-Object {${Env:@FMT} -f $PSItem,''}; Exit -Not $? }"
ENDLOCAL
EXIT /B
14 changes: 0 additions & 14 deletions Script/Map.Clear.CMD

This file was deleted.

14 changes: 8 additions & 6 deletions Script/Map.Destroy.CMD
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
::@author FB
::@version 0.1.0
::@version 0.2.0

::Ïú»Ù
:: ²ÎÊý1: ʵÀýÃû³Æ

::Script:Map.Destroy.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CALL SET "@=%%%~1.@MAP%%"
FOR %%A IN (%@%) DO (
SET "%~1.%%~A="
)
SET "%~1.@MAP="
CALL SET "@=%%%~1.@LIST%%"
FOR %%A IN (%@%) DO SET "%~1.%%~A="
CALL SET "@=%%%~1.@CHILD%%"
FOR %%A IN (%@%) DO CALL Map.Destroy.CMD "%~1.%%~A"
SET "%~1.@LIST=" & SET "%~1.@CHILD="
EXIT /B
16 changes: 16 additions & 0 deletions Script/Map.List.CMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
::@author FB
::@version 0.2.0

::遍历
:: 参数1: 实例名称
:: 参数2: 输出格式({0}键占位符, {1}值占位符)
:: 输出: 格式化后的多行字符串

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@ECHO OFF
SETLOCAL
SET "@PREFIX=%~1." & SET "@FMT=%~2"
Powershell.EXE -Command "& { Get-Item Env:${Env:@PREFIX}@LIST -ErrorAction Ignore | ForEach-Object Value | ForEach-Object {$PSItem.Split(';',[StringSplitOptions]::RemoveEmptyEntries)} | ForEach-Object {$e=(Get-Item Env:${Env:@PREFIX}$PSItem -ErrorAction Ignore);IF ($e -eq $null) {New-Object System.Collections.DictionaryEntry($PSItem,'')} else {$e.name=$PSItem};$e} | ForEach-Object {${Env:@FMT} -f $PSItem.Name,$PSItem.Value}; Exit -Not $? }"
ENDLOCAL
EXIT /B
11 changes: 8 additions & 3 deletions Script/Map.New.CMD
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
::@author FB
::@version 0.1.0
::@version 0.2.0

::数据组织: A.XX=* A.YY=* A.ZZ=*
::数据列表: %A.@MAP%
::元素列表: A.@LIST A.B.@LIST A.C.@LIST
::子项列表: A.@CHILD A.B.@CHILD A.C.@CHILD
::数据创建: CALL Map_New.CMD A;
::数据添加: CALL Map_Push.CMD A XX "*";
::数据访问: CALL Map_Get.CMD A XX; CALL :ARRAY_REMOVE A YY;
Expand All @@ -12,7 +13,11 @@
::创建
:: 参数1: 实例名称

::Script:Map.Destroy.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET "%~1.@MAP=;"
CALL Map.Destroy.CMD "%~1"
SET "%~1.@LIST=;"
SET "%~1.@CHILD=;"
EXIT /B
16 changes: 16 additions & 0 deletions Script/Map.NewChild.CMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
::@author FB
::@version 0.2.0

::创建子项
:: 参数1: 实例名称
:: 参数2: 子项名称

::Script:Map.New.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CALL ECHO.%%%~1.@CHILD%% | FIND /I ";%~2;" 1>NUL 2>&1 || (
CALL SET "%~1.@CHILD=%%%~1.@CHILD%%%~2;"
CALL Map.New.CMD "%~1.%~2"
)
EXIT /B
6 changes: 3 additions & 3 deletions Script/Map.Put.CMD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
::@author FB
::@version 0.1.0
::@version 0.2.0

::加入
:: 参数1: 实例名称
Expand All @@ -9,6 +9,6 @@
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET "%~1.%~2=%~3"
CALL ECHO.%%%~1.@MAP%% | FIND /I ";%~2;" 1>NUL 2>&1 ^
|| CALL SET "%~1.@MAP=%%%~1.@MAP%%%~2;"
CALL ECHO.%%%~1.@LIST%% | FIND /I ";%~2;" 1>NUL 2>&1 ^
|| CALL SET "%~1.@LIST=%%%~1.@LIST%%%~2;"
EXIT /B
12 changes: 0 additions & 12 deletions Script/Object.Destroy.CMD

This file was deleted.

16 changes: 0 additions & 16 deletions Script/Object.List.CMD

This file was deleted.

16 changes: 0 additions & 16 deletions Script/Object.ListAll.CMD

This file was deleted.

Loading

0 comments on commit df90387

Please sign in to comment.