Skip to content

Commit bc14ab8

Browse files
AtharvaCopilot
andcommitted
fix: handle @file.yaml in hierarchy-spec parser (P1 bug)
When user passes @file.yaml, Azure CLI framework pre-loads the file content and passes YAML text as the value. Parser now handles 3 modes: 1. File path: hierarchy.yaml (reads file) 2. YAML content: @hierarchy.yaml (CLI pre-loads, parser detects YAML) 3. Shorthand: name=X level=Y (key=value pairs) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 288136b commit bc14ab8

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

  • src/workload-orchestration/azext_workload_orchestration

src/workload-orchestration/azext_workload_orchestration/_params.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,39 @@ def load_arguments(self, _): # pylint: disable=unused-argument
9999

100100

101101
def _parse_hierarchy_spec(value):
102-
"""Parse hierarchy spec from file path or shorthand syntax."""
102+
"""Parse hierarchy spec from file path, YAML content, or shorthand syntax.
103+
104+
Handles three input modes:
105+
1. File path: 'hierarchy.yaml' or '@hierarchy.yaml' (@ stripped by CLI)
106+
2. YAML content: when CLI framework pre-loads @file, we get raw YAML text
107+
3. Shorthand: 'name=X level=Y type=Z'
108+
"""
103109
import os
104110

105-
# Handle @file syntax (@ may be stripped by CLI framework)
111+
# Mode 1: File path (with or without @)
106112
filepath = value.lstrip('@')
107113
if os.path.exists(filepath):
108114
try:
109115
import yaml
110116
except ImportError:
111-
import json as yaml_fallback
117+
import json
112118
with open(filepath, 'r', encoding='utf-8') as f:
113-
return yaml_fallback.load(f)
119+
return json.load(f)
114120
with open(filepath, 'r', encoding='utf-8') as f:
115121
return yaml.safe_load(f)
116122

117-
# Shorthand: name=X level=Y type=Z
123+
# Mode 2: YAML content (CLI framework pre-loaded @file)
124+
# Detect YAML by checking for colon-separated key-value or newlines
125+
if ':' in value and ('\n' in value or 'name:' in value or 'level:' in value):
126+
try:
127+
import yaml
128+
parsed = yaml.safe_load(value)
129+
if isinstance(parsed, dict):
130+
return parsed
131+
except Exception:
132+
pass
133+
134+
# Mode 3: Shorthand syntax: name=X level=Y type=Z
118135
result = {}
119136
for pair in value.split():
120137
if '=' in pair:

0 commit comments

Comments
 (0)