🔥 소개

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

채널 보기
관점 지향 로깅 인터셉터 구현 및 전역 바인딩 전략 | NestJS 가이드
NestJS 인터셉터에서 map 연산자로 응답을 변환하는 방법 | NestJS 가이드
API 응답 지연과 복잡한 에러, NestJS 인터셉터로 관리하는 방법 | NestJS 가이드
class-validator 와 DTO | NestJS 가이드
입력을 전처리하는 Functor - Contravariant와 contramap 이해하기 | 프로그래머를 위한 카테고리 이론
Writer 펑터와 클라이슬리 카테고리 | 프로그래머를 위한 카테고리 이론
미들웨어 vs 가드, 왜 NestJS에서는 가드가 더 똑똑할까? | NestJS 가이드
변환 파이프로 컨트롤러 코드 깔끔하게 만들기 | NestJS 가이드