ArgumentParser/ParsableCommandParsableCommand types are the basic building blocks for command-line tools built using ArgumentParser. To create a command, declare properties using the @Argument, @Option, and @Flag property wrappers, or include groups of options with @OptionGroup. Finally, implement your command's functionality in the run()-7p2fr method.
@main
struct Repeat: ParsableCommand {
@Argument(help: "The phrase to repeat.")
var phrase: String
@Option(help: "The number of times to repeat 'phrase'.")
var count: Int? = nil
mutating func run() throws {
let repeatCount = count ?? 2
for _ in 0..<repeatCount {
print(phrase)
}
}
}
Note: The Swift compiler uses either the type marked with
@mainor amain.swiftfile as the entry point for an executable program. You can use either one, but not both — rename yourmain.swiftfile to the name of the command when you add@main.
run()-7p2frParsableArguments/validate()-5r0geconfiguration-35km1CommandConfigurationhelpMessage(for:includeHidden:columns:)main()main(_:)parseAsRoot(_:)