🔥 도움말 플래그 이름 수정하기

241자
2분

사용자는 -h--help 플래그를 전달하여 명령어 도움말 화면을 볼 수 있습니다. 만약 -h--help 플래그를 다른 용도로 사용해야 한다면, 루트 명령어를 정의할 때 help 플래그에 다른 이름을 지정할 수 있습니다.

swift
struct Example: ParsableCommand {
    static let configuration = CommandConfiguration(
        helpNames: [.long, .customShort("?")])
 
    @Option(name: .shortAndLong, help: "The number of history entries to show.")
    var historyDepth: Int
 
    mutating func run() throws {
        printHistory(depth: historyDepth)
    }
}
 
swift
struct Example: ParsableCommand {
    static let configuration = CommandConfiguration(
        helpNames: [.long, .customShort("?")])
 
    @Option(name: .shortAndLong, help: "The number of history entries to show.")
    var historyDepth: Int
 
    mutating func run() throws {
        printHistory(depth: historyDepth)
    }
}
 

명령어를 실행할 때 -hhistoryDepth 속성을 나타내는 짧은 이름으로 사용하고, -?는 도움말 화면을 표시하는 옵션으로 사용합니다:

text
% example -h 3
nmap -v -sS -O 10.2.2.2
sshnuke 10.2.2.2 -rootpw="Z1ON0101"
ssh 10.2.2.2 -l root
% example -?
USAGE: example --history-depth <history-depth>

ARGUMENTS:
  <phrase>                The phrase to repeat.

OPTIONS:
  -h, --history-depth     The number of history entries to show.
  -?, --help              Show help information.
text
% example -h 3
nmap -v -sS -O 10.2.2.2
sshnuke 10.2.2.2 -rootpw="Z1ON0101"
ssh 10.2.2.2 -l root
% example -?
USAGE: example --history-depth <history-depth>

ARGUMENTS:
  <phrase>                The phrase to repeat.

OPTIONS:
  -h, --history-depth     The number of history entries to show.
  -?, --help              Show help information.

이 예제에서 부모 명령어는 --help-?를 도움말 옵션으로 정의합니다. 따로 지정하지 않으면, 하위 명령어들은 이 도움말 옵션을 그대로 상속합니다.

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

위 코드에서 child 하위 명령어는 부모 도움말 이름을 상속하기 때문에 사용자는 -h 를 사용하여 호스트 정보를, -? 를 사용하여 자세한 도움말을 확인할 수 있습니다.

text
% parent child -h 192.0.0.0
...
% parent child -?
USAGE: parent child --host <host>

OPTIONS:
  -h, --host <host>       The host the server will run on.
  -?, --help              Show help information.
text
% parent child -h 192.0.0.0
...
% parent child -?
USAGE: parent child --host <host>

OPTIONS:
  -h, --host <host>       The host the server will run on.
  -?, --help              Show help information.

YouTube 영상

채널 보기
벡터의 정의와 덧셈 연산 | 선형대수학
Trie 자료구조 완전 정복 - 개념부터 시각화까지 | Trie 자료구조 이야기
AI를 위한 선형대수학 - 소개 | 선형대수학
13편, 인덱스가 많으면 왜 느려질까? 쓰기 증폭과 인덱스 튜닝의 이해
우리가 매일 쓰는 맞춤법 검사기와 라우터 속에 숨겨진 알고리즘은? | Trie 자료구조 이야기
숫자 하나가 AI 모델의 운명을 바꾼다? | 선형대수학
트라이(Trie) 자료구조: 파이썬으로 삽입(Insert) 연산 구현하기 | Trie 자료구조 이야기
Trie 자료구조 완전 정복 - 개념부터 시각화까지 | Trie 자료구조 이야기