Avatar
norio_nomura 2/28/2020 2:21 AM
https://swift.org/blog/argument-parser/ Swift Argument Parserをインポートできるようにしました。 @swift-main @swift-5.2.5 - --help import ArgumentParser struct Repeat: ParsableCommand { @Flag(help: "Include a counter with each repetition.") var includeCounter: Bool @Option(name: .shortAndLong, help: "The number of times to repeat 'phrase'.") var count: Int? @Argument(help: "The phrase to repeat.") var phrase: String } extension Repeat { func run() throws { let repeatCount = count ?? .max for i in 1...repeatCount { if includeCounter { print("\(i): \(phrase)") } else { print(phrase) } } } } Repeat.main() (edited)