mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-07-13 22:35:16 +03:00
feat(skd-edit): add patch-query operation for substring replacement in queries
Addresses user feedback: set-query is all-or-nothing, and editing XML directly is fragile due to escaping. patch-query allows targeted string replacement via "old => new" shorthand, with batch mode support. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -163,6 +163,15 @@ Shorthand: `"Параметр = значение [when условие] [for По
|
||||
|
||||
Не поддерживает пакетный режим. Value — полный текст запроса или `@path/to/file.sql` (ссылка на внешний файл). Путь разрешается относительно Template.xml, затем CWD.
|
||||
|
||||
### patch-query — точечная замена в тексте запроса
|
||||
|
||||
Shorthand: `"старое => новое"`. Заменяет все вхождения подстроки. Поддерживает пакетный режим и `-DataSet`.
|
||||
|
||||
```
|
||||
"СубконтоДт1) В => СубконтоКт1) В"
|
||||
"ЛЕВОЕ СОЕДИНЕНИЕ => ВНУТРЕННЕЕ СОЕДИНЕНИЕ"
|
||||
```
|
||||
|
||||
### set-outputParameter — установить параметр вывода
|
||||
|
||||
```
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# skd-edit v1.2 — Atomic 1C DCS editor
|
||||
# skd-edit v1.3 — Atomic 1C DCS editor
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
@@ -9,7 +9,7 @@ param(
|
||||
"add-field","add-total","add-calculated-field","add-parameter","add-filter",
|
||||
"add-dataParameter","add-order","add-selection","add-dataSetLink",
|
||||
"add-dataSet","add-variant","add-conditionalAppearance",
|
||||
"set-query","set-outputParameter","set-structure",
|
||||
"set-query","patch-query","set-outputParameter","set-structure",
|
||||
"modify-field","modify-filter","modify-dataParameter",
|
||||
"clear-selection","clear-order","clear-filter",
|
||||
"remove-field","remove-total","remove-calculated-field","remove-parameter","remove-filter")]
|
||||
@@ -1740,6 +1740,34 @@ switch ($Operation) {
|
||||
Write-Host "[OK] Query replaced in dataset `"$dsName`""
|
||||
}
|
||||
|
||||
"patch-query" {
|
||||
$dsNode = Resolve-DataSet
|
||||
$dsName = Get-DataSetName $dsNode
|
||||
|
||||
$queryEl = Find-FirstElement $dsNode @("query") $schNs
|
||||
if (-not $queryEl) {
|
||||
Write-Error "No <query> element found in dataset '$dsName'"
|
||||
exit 1
|
||||
}
|
||||
|
||||
foreach ($val in $values) {
|
||||
$sepIdx = $val.IndexOf(" => ")
|
||||
if ($sepIdx -lt 0) {
|
||||
Write-Error "patch-query value must contain ' => ' separator: old => new"
|
||||
exit 1
|
||||
}
|
||||
$oldStr = $val.Substring(0, $sepIdx)
|
||||
$newStr = $val.Substring($sepIdx + 4)
|
||||
$queryText = $queryEl.InnerText
|
||||
if (-not $queryText.Contains($oldStr)) {
|
||||
Write-Error "Substring not found in query of dataset '$dsName': $oldStr"
|
||||
exit 1
|
||||
}
|
||||
$queryEl.InnerText = $queryText.Replace($oldStr, $newStr)
|
||||
Write-Host "[OK] Query patched in dataset `"$dsName`": replaced '$oldStr'"
|
||||
}
|
||||
}
|
||||
|
||||
"set-outputParameter" {
|
||||
$settings = Resolve-VariantSettings
|
||||
$varName = Get-VariantName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# skd-edit v1.2 — Atomic 1C DCS editor (Python port)
|
||||
# skd-edit v1.3 — Atomic 1C DCS editor (Python port)
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
import argparse
|
||||
import os
|
||||
@@ -17,7 +17,7 @@ VALID_OPS = [
|
||||
"add-field", "add-total", "add-calculated-field", "add-parameter", "add-filter",
|
||||
"add-dataParameter", "add-order", "add-selection", "add-dataSetLink",
|
||||
"add-dataSet", "add-variant", "add-conditionalAppearance",
|
||||
"set-query", "set-outputParameter", "set-structure",
|
||||
"set-query", "patch-query", "set-outputParameter", "set-structure",
|
||||
"modify-field", "modify-filter", "modify-dataParameter",
|
||||
"clear-selection", "clear-order", "clear-filter",
|
||||
"remove-field", "remove-total", "remove-calculated-field", "remove-parameter", "remove-filter",
|
||||
@@ -1488,6 +1488,27 @@ elif operation == "set-query":
|
||||
query_el.text = resolve_query_value(value_arg, query_base_dir)
|
||||
print(f'[OK] Query replaced in dataset "{ds_name}"')
|
||||
|
||||
elif operation == "patch-query":
|
||||
ds_node = resolve_data_set()
|
||||
ds_name = get_data_set_name(ds_node)
|
||||
query_el = find_first_element(ds_node, ["query"], SCH_NS)
|
||||
if query_el is None:
|
||||
print(f"No <query> element found in dataset '{ds_name}'", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
for val in values:
|
||||
sep_idx = val.find(" => ")
|
||||
if sep_idx < 0:
|
||||
print("patch-query value must contain ' => ' separator: old => new", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
old_str = val[:sep_idx]
|
||||
new_str = val[sep_idx + 4:]
|
||||
query_text = query_el.text or ""
|
||||
if old_str not in query_text:
|
||||
print(f"Substring not found in query of dataset '{ds_name}': {old_str}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
query_el.text = query_text.replace(old_str, new_str)
|
||||
print(f'[OK] Query patched in dataset "{ds_name}": replaced \'{old_str}\'')
|
||||
|
||||
elif operation == "set-outputParameter":
|
||||
settings = resolve_variant_settings()
|
||||
var_name = get_variant_name()
|
||||
|
||||
Reference in New Issue
Block a user