feat: config 파일을 CLI 설정 소스로 활용#27
Merged
Merged
Conversation
`hwp2md config set`이 이슈 #19에서 명세한 키들을 모두 처리하도록 확장하고, `convert` 커맨드가 설정 파일을 실제로 읽어 동작에 반영하도록 wire-up 한다. 우선순위는 CLI 플래그 > 환경 변수 > 설정 파일 > 코드 기본값으로 통일한다. 추가된 설정 키: - parser (native, upstage) - llm.enabled (true/false) - llm.provider (openai, anthropic, gemini, upstage, ollama) - llm.model - llm.base_url (URL 형식 검증) - llm.timeout (Go 기간 문자열, 양수) Config 구조체에 `Parser`와 `LLM` 그룹을 추가하되, 기존 `default_provider`, `providers.*`, `format.*` 키는 호환성 유지를 위해 그대로 남겨둔다. 실패 시 동작 차단을 피하려고 `loadAppConfig`는 파일 부재/파싱 오류 모두 DefaultConfig로 폴백한다(플래그/환경변수가 우선이므로 안전). `llm.timeout` 키는 추가하지만, `convert.go`의 timeout 처리 wire-up은 PR #26에 의존하므로 본 PR에는 포함하지 않는다(#26 머지 후 follow-up). Closes #19 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PR #19 description에서 PR #26 머지 후 follow-up으로 약속한 마지막 결합. `parseLLMTimeout` 시그니처에 `configVal` 파라미터를 추가해 우선순위 flag > env > config > provider default를 단일 resolver로 처리한다. 잘못된 값 입력 시 source-specific 에러("--timeout"/"HWP2MD_TIMEOUT"/ "config llm.timeout")로 어디서 들어왔는지 명확히 알린다. 테스트는 13 → 18 케이스로 확장: config 정상 fallback, env/flag와의 우선순위 교차, whitespace 폴백, source-specific 에러 검증을 추가. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5d71a45 to
7e7434c
Compare
Windows의 os.UserHomeDir()은 HOME이 아닌 USERPROFILE을 보므로 t.Setenv(\"HOME\", tmpHome)만으로는 격리되지 않아 진짜 user home에 config 파일을 만들고, 같은 runner의 e2e 테스트가 그 파일을 읽어 LLM Stage 2(upstage)를 켜면서 UPSTAGE_API_KEY 부재로 실패했다. HOME과 USERPROFILE을 모두 tmpDir로 redirect해 OS와 무관하게 격리되도록 한다. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
이슈 #19에서 요청한
config명령 마무리:parser,llm.enabled,llm.provider,llm.model,llm.base_url,llm.timeout)을hwp2md config set에서 처리convert커맨드가 설정 파일을 실제로 읽어서 동작에 반영하도록 wire-upWhy
기존에는
config show/init/set/path가 동작은 했지만,convert명령은 환경변수만 보고 설정 파일을 무시했습니다. 이슈 #19의 핵심은 설정 파일을 신뢰 가능한 소스로 만드는 것입니다.Changes
internal/config/config.goConfig에Parser string필드와LLM LLMConfig그룹(Enabled/Provider/Model/BaseURL/Timeout) 추가default_provider,providers.*,format.*은 호환성 유지(YAML 태그에omitempty)internal/cli/config.goconfig set에 새 키 처리 추가, 각각 검증 적용:parser—native/upstage만 허용llm.enabled—strconv.ParseBoolllm.provider— 5종(openai/anthropic/gemini/upstage/ollama)llm.model— 비어있지 않은 문자열llm.base_url—url.Parse+ scheme/host 검증llm.timeout—time.ParseDuration+ 양수 검사Longhelp/예시 갱신internal/cli/convert.goloadAppConfig()— 설정 파일 로드, 실패 시DefaultConfig()폴백 (플래그/환경변수가 우선이라 안전)resolveString(flag, env, cfg, default)— 우선순위 헬퍼, 공백은 빈 값 취급parser,llm.enabled,llm.provider,llm.model,llm.base_url5개 항목에 적용formatWithLLM이*config.Config를 인자로 받도록 시그니처 확장Tests
internal/config/config_test.go—TestConfig_LLMRoundTrip(YAML 저장/복원)internal/cli/cli_test.go:TestResolveString— flag/env/config/default 우선순위 6 케이스TestRunConfigSet_NewKeys— 새 키 8개 × 성공/검증 실패 합 14 케이스 (HOME 격리 사용)Docs
CLAUDE.md— 우선순위 명시, config 키 표 추가의도적 미포함
llm.timeoutconfig 값을 실제 LLM 호출에 반영하는 wire-up은 PR #26 (fix/24-configurable-llm-timeout)에 의존합니다. #26 머지 후 follow-up 1줄 변경으로 결합 예정 — 본 PR에 포함하면 시그니처 충돌이 생겨 분리했습니다. 본 PR로도config set llm.timeout 5m은 정상 저장/검증되며, #26이 머지되는 순간 설정 파일 값까지 자동 반영됩니다.Test plan
make fmt— no diffmake lint— cleango test ./...— 전체 통과 (e2e 포함)hwp2md config init && config set parser/llm.* && config showround-trip 수동 확인parser bogus,llm.timeout abc,llm.base_url localhost:11434,llm.enabled yesno) 한국어 출력 확인convert가 정상 동작(폴백) 확인Closes #19
관련: #26 (timeout wire-up follow-up)
🤖 Generated with Claude Code