🔥 소개

166자
2분

사용자와 스스로를 돕기 위해 매개변수, 옵션 및 플래그에 대한 풍부한 도움말을 제공합시다. @Argument, @Option 또는 @Flag를 선언할 때 help 매개변수로 문자열 리터럴을 전달하여 도움말 텍스트를 제공할 수 있습니다.

swift
struct Example: ParsableCommand {
    @Flag(help: "Display extra information while processing.")
    var verbose = false
 
    @Option(help: "The number of extra lines to show.")
    var extraLines = 0
 
    @Argument(help: "The input file.")
    var inputFile: String?
}
 
swift
struct Example: ParsableCommand {
    @Flag(help: "Display extra information while processing.")
    var verbose = false
 
    @Option(help: "The number of extra lines to show.")
    var extraLines = 0
 
    @Argument(help: "The input file.")
    var inputFile: String?
}
 

이런 문자열은 기본적으로 -h 또는 --help 플래그로 트리거되는 자동 생성된 도움말 화면에서 볼 수 있죠.

text
% example --help
USAGE: example [--verbose] [--extra-lines <extra-lines>] <input-file>

ARGUMENTS:
  <input-file>            The input file.

OPTIONS:
  --verbose               Display extra information while processing.
  --extra-lines <extra-lines>
                          The number of extra lines to show. (default: 0)
  -h, --help              Show help information.
text
% example --help
USAGE: example [--verbose] [--extra-lines <extra-lines>] <input-file>

ARGUMENTS:
  <input-file>            The input file.

OPTIONS:
  --verbose               Display extra information while processing.
  --extra-lines <extra-lines>
                          The number of extra lines to show. (default: 0)
  -h, --help              Show help information.

이렇게 제공되는 도움말은 사용자가 명령줄 도구를 더 쉽게 이해하고 사용할 수 있도록 돕습니다. 개발자 역시 이러한 도움말을 통해 인터페이스를 더 잘 문서화하고 관리할 수 있어요. help 매개변수의 문자열은 간결하면서도 명확해야 합니다. 해당 인자나 옵션의 목적과 동작을 잘 설명해야 하죠. 기본값이 있다면 이를 명시하는 것도 좋은 방법입니다.

YouTube 영상

채널 보기
AI는 왜 수백 차원의 벡터를 사용할까? 고차원 공간과 행렬 | 선형대수학
10편, 파이썬으로 구현하는 B+ Tree
AI에서 고차원 임베딩이 무엇일까?
11편, 왜 DB마다 성능이 다를까? 엔진별 B-Tree 저장 방식 비교
Trie 자료구조 파이썬 구현: Search와 Starts With 연산 | Trie 자료구조 이야기
AI는 데이터를 어떻게 분류할까? 벡터의 거리와 KNN 알고리즘 | 선형대수학
3편, B-Tree 탐색 프로세스: 수백 개의 갈림길에서 데이터를 찾는 법
5편, B-Tree 내부 노드에서 키를 삭제할 때 정렬 규칙을 지키는 방법