🔥 공통 인자 정의하기

73자
1분

다음으로, 여러 하위 명령어에서 공유할 속성을 가진 ParsableArguments 타입을 정의해요. ParsableArguments를 채택한 타입은 커맨드 라인 인자를 파싱할 수 있지만, run() 메서드를 통한 실행 기능은 제공하지 않을 수 있어요.

이 경우 Options 타입은 --hexadecimal-output 플래그를 받고 정수 리스트를 인자로 전달받습니다.

swift
struct Options: ParsableArguments {
    @Flag(name: [.long, .customShort("x")], help: "Use hexadecimal notation for the result.")
    var hexadecimalOutput = false
 
    @Argument(help: "A group of integers to operate on.")
    var values: [Int]
}
swift
struct Options: ParsableArguments {
    @Flag(name: [.long, .customShort("x")], help: "Use hexadecimal notation for the result.")
    var hexadecimalOutput = false
 
    @Argument(help: "A group of integers to operate on.")
    var values: [Int]
}

YouTube 영상

채널 보기
C++ 속의 펑터 | 프로그래머를 위한 카테고리 이론
인터셉터와 RxJS로 캐시 시스템 구축하기 | NestJS 가이드
입력을 전처리하는 Functor - Contravariant와 contramap 이해하기 | 프로그래머를 위한 카테고리 이론
함수 객체의 보편적 구성 | 프로그래머를 위한 카테고리 이론
함수 타입과 Hom-Set 이해하기 | 프로그래머를 위한 카테고리 이론
관점 지향 로깅 인터셉터 구현 및 전역 바인딩 전략 | NestJS 가이드
NestJS 커스텀 데코레이터, createParamDecorator 사용 | NestJS 가이드
NestJS 가드, 바이딩과 스코프 | NestJS 가이드