🔥 명령어 숨기기

98자
1분

명령줄 인터페이스 일부로 모든 명령어를 표시하고 싶지 않을 수도 있습니다. 명령어를 보이지 않게 만들려면(그러나 여전히 사용할 수 있음) CommandConfiguration 이니셜라이저에 shouldDisplay: false를 전달합니다.

아래와 같이 Child 명령어에 shouldDisplay: false를 추가하여 간단하게 숨길 수 있습니다:

swift
struct Parent: ParsableCommand {
    static let configuration = CommandConfiguration(
        subcommands: [Child.self],
        helpNames: [.long, .customShort("?")])
 
    struct Child: ParsableCommand {
        static let configuration = CommandConfiguration(
            shouldDisplay: false
        )
 
        @Option(name: .shortAndLong, help: "The host the server will run on.")
        var host: String
    }
}
 
swift
struct Parent: ParsableCommand {
    static let configuration = CommandConfiguration(
        subcommands: [Child.self],
        helpNames: [.long, .customShort("?")])
 
    struct Child: ParsableCommand {
        static let configuration = CommandConfiguration(
            shouldDisplay: false
        )
 
        @Option(name: .shortAndLong, help: "The host the server will run on.")
        var host: String
    }
}
 

이제 Child 명령어는 Parent 명령어 도움말에는 표시되지 않지만, 여전히 parent child --host <host>와 같이 직접 실행할 수 있습니다.

YouTube 영상

채널 보기
AI는 왜 수백 차원의 벡터를 사용할까? 고차원 공간과 행렬 | 선형대수학
마지막편, 트라이 노드를 50% 이상 줄이는 방법? 압축 트라이 성능 분석 | Trie 자료구조 이야기
행렬의 기본 연산 - 행렬 덧셈, 스칼라 곱, 전치 | 선형대수학
AI를 위한 선형대수학 - 소개 | 선형대수학
트라이(Trie) 자료구조: 파이썬으로 삽입(Insert) 연산 구현하기 | Trie 자료구조 이야기
행렬의 가장 중요한 연산 - 행렬 곱셈 | 선형대수학
스칼라 곱셈과 내적의 기하학적 의미 | 선형대수학
우리가 매일 쓰는 맞춤법 검사기와 라우터 속에 숨겨진 알고리즘은? | Trie 자료구조 이야기