🔥 소개
166자
2분
사용자와 스스로를 돕기 위해 매개변수, 옵션 및 플래그에 대한 풍부한 도움말을 제공합시다. @Argument, @Option 또는 @Flag를 선언할 때 help 매개변수로 문자열 리터럴을 전달하여 도움말 텍스트를 제공할 수 있습니다.
swift
struct Example: ParsableCommand {
@Flag(help: "Display extra information while processing.")
var verbose = false
@Option(help: "The number of extra lines to show.")
var extraLines = 0
@Argument(help: "The input file.")
var inputFile: String?
}
swift
struct Example: ParsableCommand {
@Flag(help: "Display extra information while processing.")
var verbose = false
@Option(help: "The number of extra lines to show.")
var extraLines = 0
@Argument(help: "The input file.")
var inputFile: String?
}
이런 문자열은 기본적으로 -h 또는 --help 플래그로 트리거되는 자동 생성된 도움말 화면에서 볼 수 있죠.
text
% example --help
USAGE: example [--verbose] [--extra-lines <extra-lines>] <input-file>
ARGUMENTS:
<input-file> The input file.
OPTIONS:
--verbose Display extra information while processing.
--extra-lines <extra-lines>
The number of extra lines to show. (default: 0)
-h, --help Show help information.
text
% example --help
USAGE: example [--verbose] [--extra-lines <extra-lines>] <input-file>
ARGUMENTS:
<input-file> The input file.
OPTIONS:
--verbose Display extra information while processing.
--extra-lines <extra-lines>
The number of extra lines to show. (default: 0)
-h, --help Show help information.
이렇게 제공되는 도움말은 사용자가 명령줄 도구를 더 쉽게 이해하고 사용할 수 있도록 돕습니다. 개발자 역시 이러한 도움말을 통해 인터페이스를 더 잘 문서화하고 관리할 수 있어요. help 매개변수의 문자열은 간결하면서도 명확해야 합니다. 해당 인자나 옵션의 목적과 동작을 잘 설명해야 하죠. 기본값이 있다면 이를 명시하는 것도 좋은 방법입니다.











