mirror of
https://github.com/apple/swift-argument-parser.git
synced 2026-05-07 20:12:41 +00:00
83ad8da9d0
* docs: update help text for readability in Repeat example and README * Update help text snapshots for repeat command to fix test failures
37 lines
950 B
Swift
37 lines
950 B
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
|
|
|
|
@main
|
|
struct Repeat: ParsableCommand {
|
|
@Option(help: "How many times to repeat 'phrase'.")
|
|
var count: Int? = nil
|
|
|
|
@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 ?? 2
|
|
|
|
for i in 1...repeatCount {
|
|
if includeCounter {
|
|
print("\(i): \(phrase)")
|
|
} else {
|
|
print(phrase)
|
|
}
|
|
}
|
|
}
|
|
}
|