🔥 소개

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 영상

채널 보기
Product와 Coproduct가 Bifunctor인 이유 | 프로그래머를 위한 카테고리 이론
Writer 펑터와 클라이슬리 카테고리 | 프로그래머를 위한 카테고리 이론
NestJS 빌트인 파이프 ParseIntPipe, ParseUUIDPipe 사용하기 | NestJS 가이드
존 매카시가 들려주는 인공지능의 탄생 이야기
입력을 전처리하는 Functor - Contravariant와 contramap 이해하기 | 프로그래머를 위한 카테고리 이론
클로드 섀넌이 들려주는 정보 이론 이야기
미들웨어 vs 가드, 왜 NestJS에서는 가드가 더 똑똑할까? | NestJS 가이드
바이펑터란? | 프로그래머를 위한 카테고리 이론