---
# [샘플] 문자열 처리 + JSON 읽기/쓰기

property:
  workspace: /path/to/project
  rawVersion: "v1.2.3-release"
  payload: '{"status": "ok", "build": {"version": "1.2.3", "number": 42}}'

pipeline:
  id: main
  workflow:
  - exe: string-sub       # 부분 문자열 추출
  - exe: string-replace   # 문자열 치환
  - exe: string-pattern   # 정규식 치환
  - exe: string-index     # 인덱스 검색
  - exe: json-read        # JSON 값 추출
  - exe: json-read-file   # JSON 파일 읽기
  - exe: json-write-file  # JSON 파일 쓰기
  - exe: print-results

commands:
# 부분 문자열 (startIndex, lastIndex: 0-based, -1은 끝까지)
- command: StringSub
  id: string-sub
  param:
    text: <!property.rawVersion>
    startIndex: 1      # "v" 제거
    lastIndex: -1
    setValue: <@property.version>

# 문자열 치환
- command: StringReplace
  id: string-replace
  param:
    text: <!property.rawVersion>
    pair:
    - from: "v"
      to: ""
    - from: "-release"
      to: ""
    setValue: <@property.cleanVersion>

# 정규식 치환
- command: StringReplacePattern
  id: string-pattern
  param:
    text: <!property.rawVersion>
    pattern: "[^0-9.]"   # 숫자와 점만 남김
    replace: ""
    setValue: <@property.numericVersion>

# 문자열 내 인덱스 검색
- command: StringIndex
  id: string-index
  param:
    text: <!property.rawVersion>
    find: "-"
    setValue: <@property.dashIndex>

# JSON 문자열에서 값 추출
- command: JsonReader
  id: json-read
  param:
    json: <!property.payload>
    pair:
    - from: status
      setValue: <@property.apiStatus>
    - from: build.version        # 중첩 키
      setValue: <@property.buildVersion>
    - from: build.number
      setValue: <@property.buildNumber>

# JSON 파일에서 값 읽기
- command: JsonReaderFile
  id: json-read-file
  param:
    path: <!property.workspace>/config/settings.json
    pair:
    - from: apiKey
      setValue: <@property.apiKey>

# JSON 파일에 값 쓰기
- command: JsonWriterFile
  id: json-write-file
  param:
    path: <!property.workspace>/config/settings.json
    pair:
    - from: version
      value: <!property.cleanVersion>
    - from: buildNumber
      value: <!property.buildNumber>

- command: Print
  id: print-results
  param:
    message: "버전: <!property.cleanVersion>, 빌드: <!property.buildNumber>, 상태: <!property.apiStatus>"
