mirror of
https://github.com/apple/swift-argument-parser.git
synced 2026-06-06 20:18:23 +00:00
* Use type inference for flags / options * Use default value syntax for arg/option arrays * Allow a default for flag arrays * Fix some whitespace * Allow arguments validations to warn instead of fail * Move nonsense flag warning to argument validation * Update guides/readme with default literal syntax
38 lines
1023 B
Swift
38 lines
1023 B
Swift
//===----------------------------------------------------------*- swift -*-===//
|
|
//
|
|
// This source file is part of the Swift Argument Parser open source project
|
|
//
|
|
// Copyright (c) 2020 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import ArgumentParser
|
|
|
|
struct Repeat: ParsableCommand {
|
|
@Option(help: "The number of times to repeat 'phrase'.")
|
|
var count: Int?
|
|
|
|
@Flag(help: "Include a counter with each repetition.")
|
|
var includeCounter = false
|
|
|
|
@Argument(help: "The phrase to repeat.")
|
|
var phrase: String
|
|
|
|
mutating func run() throws {
|
|
let repeatCount = count ?? .max
|
|
|
|
for i in 1...repeatCount {
|
|
if includeCounter {
|
|
print("\(i): \(phrase)")
|
|
} else {
|
|
print(phrase)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Repeat.main()
|