🔥 공통 인자 정의하기

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

채널 보기
스칼라 곱셈과 내적의 기하학적 의미 | 선형대수학
내적의 기하학적 의미와 코사인 유사도 원리 | 선형대수학
트라이(Trie)에서 단어를 삭제하는 방법 | Trie 자료구조 이야기
Trie(트라이) 자료구조 원리와 파이썬 클래스 설계 및 구현 | Trie 자료구조 이야기
우리가 매일 쓰는 맞춤법 검사기와 라우터 속에 숨겨진 알고리즘은? | Trie 자료구조 이야기
트라이(Trie)를 이용한 자동 완성 알고리즘 | Trie 자료구조 이야기
7편, 파이썬으로 구현하는 B-Tree
벡터의 정의와 덧셈 연산 | 선형대수학