🔥 도움말 플래그 이름 수정하기
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)
}
}
명령어를 실행할 때 -h는 historyDepth 속성을 나타내는 짧은 이름으로 사용하고, -?는 도움말 화면을 표시하는 옵션으로 사용합니다:
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.









