mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-07-13 14:25:17 +03:00
feat(skd): support @file references for query text in skd-compile and skd-edit
Allows using "@path/to/file.sql" instead of inline query text. Path resolved relative to definition file, then CWD; absolute paths supported. Closes #9 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# skd-edit v1.1 — Atomic 1C DCS editor
|
||||
# skd-edit v1.2 — Atomic 1C DCS editor
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
@@ -47,6 +47,29 @@ function Esc-Xml {
|
||||
return $s.Replace('&','&').Replace('<','<').Replace('>','>').Replace('"','"')
|
||||
}
|
||||
|
||||
function Resolve-QueryValue {
|
||||
param([string]$val, [string]$baseDir)
|
||||
if (-not $val.StartsWith("@")) { return $val }
|
||||
$filePath = $val.Substring(1)
|
||||
if ([System.IO.Path]::IsPathRooted($filePath)) {
|
||||
$candidates = @($filePath)
|
||||
} else {
|
||||
$candidates = @(
|
||||
(Join-Path $baseDir $filePath),
|
||||
(Join-Path (Get-Location).Path $filePath)
|
||||
)
|
||||
}
|
||||
foreach ($c in $candidates) {
|
||||
if (Test-Path $c) {
|
||||
return (Get-Content -Raw -Encoding UTF8 $c).TrimEnd()
|
||||
}
|
||||
}
|
||||
Write-Error "Query file not found: $filePath (searched: $($candidates -join ', '))"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$script:queryBaseDir = [System.IO.Path]::GetDirectoryName($resolvedPath)
|
||||
|
||||
# --- 2. Type system (copied from skd-compile) ---
|
||||
|
||||
$script:typeSynonyms = New-Object System.Collections.Hashtable
|
||||
@@ -1712,7 +1735,7 @@ switch ($Operation) {
|
||||
}
|
||||
|
||||
# InnerText setter handles XML escaping automatically
|
||||
$queryEl.InnerText = $Value
|
||||
$queryEl.InnerText = Resolve-QueryValue $Value $script:queryBaseDir
|
||||
|
||||
Write-Host "[OK] Query replaced in dataset `"$dsName`""
|
||||
}
|
||||
@@ -1813,6 +1836,7 @@ switch ($Operation) {
|
||||
$childIndent = Get-ChildIndent $root
|
||||
|
||||
$parsed = Parse-DataSetShorthand $Value
|
||||
$parsed.query = Resolve-QueryValue $parsed.query $script:queryBaseDir
|
||||
|
||||
# Auto-name if empty
|
||||
if (-not $parsed.name) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# skd-edit v1.1 — Atomic 1C DCS editor (Python port)
|
||||
# skd-edit v1.2 — Atomic 1C DCS editor (Python port)
|
||||
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
import argparse
|
||||
import os
|
||||
@@ -78,6 +78,25 @@ def esc_xml(s):
|
||||
return s.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"')
|
||||
|
||||
|
||||
def resolve_query_value(val, base_dir):
|
||||
if not val.startswith("@"):
|
||||
return val
|
||||
file_path = val[1:]
|
||||
if os.path.isabs(file_path):
|
||||
candidates = [file_path]
|
||||
else:
|
||||
candidates = [
|
||||
os.path.join(base_dir, file_path),
|
||||
os.path.join(os.getcwd(), file_path),
|
||||
]
|
||||
for c in candidates:
|
||||
if os.path.exists(c):
|
||||
with open(c, 'r', encoding='utf-8-sig') as f:
|
||||
return f.read().rstrip()
|
||||
print(f"Query file not found: {file_path} (searched: {', '.join(candidates)})", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def new_uuid():
|
||||
return str(uuid.uuid4())
|
||||
|
||||
@@ -94,6 +113,7 @@ if not os.path.exists(template_path):
|
||||
sys.exit(1)
|
||||
|
||||
resolved_path = os.path.abspath(template_path)
|
||||
query_base_dir = os.path.dirname(resolved_path)
|
||||
|
||||
# ── 2. Type system ──────────────────────────────────────────
|
||||
|
||||
@@ -1465,7 +1485,7 @@ elif operation == "set-query":
|
||||
if query_el is None:
|
||||
print(f"No <query> element found in dataset '{ds_name}'", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
query_el.text = value_arg
|
||||
query_el.text = resolve_query_value(value_arg, query_base_dir)
|
||||
print(f'[OK] Query replaced in dataset "{ds_name}"')
|
||||
|
||||
elif operation == "set-outputParameter":
|
||||
@@ -1541,6 +1561,7 @@ elif operation == "add-dataSetLink":
|
||||
elif operation == "add-dataSet":
|
||||
child_indent = get_child_indent(xml_doc)
|
||||
parsed = parse_data_set_shorthand(value_arg)
|
||||
parsed["query"] = resolve_query_value(parsed["query"], query_base_dir)
|
||||
|
||||
if not parsed["name"]:
|
||||
count = sum(1 for ch in xml_doc if isinstance(ch.tag, str) and local_name(ch) == "dataSet" and etree.QName(ch.tag).namespace == SCH_NS)
|
||||
|
||||
Reference in New Issue
Block a user