Skip to content

Commit 18b0039

Browse files
Fix Repeat's endless printing (#437)
Co-authored-by: Nate Cook <[email protected]>
1 parent abe33fa commit 18b0039

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

Examples/repeat/Repeat.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct Repeat: ParsableCommand {
2323
var phrase: String
2424

2525
mutating func run() throws {
26-
let repeatCount = count ?? .max
26+
let repeatCount = count ?? 2
2727

2828
for i in 1...repeatCount {
2929
if includeCounter {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct Repeat: ParsableCommand {
2323
var phrase: String
2424

2525
mutating func run() throws {
26-
let repeatCount = count ?? .max
26+
let repeatCount = count ?? 2
2727

2828
for i in 1...repeatCount {
2929
if includeCounter {

Sources/ArgumentParser/Documentation.docc/ArgumentParser.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct Repeat: ParsableCommand {
2424
var count: Int?
2525

2626
mutating func run() throws {
27-
let repeatCount = count ?? .max
27+
let repeatCount = count ?? 2
2828
for _ in 0..<repeatCount {
2929
print(phrase)
3030
}

Sources/ArgumentParser/Documentation.docc/Articles/CustomizingCommandHelp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Repeat: ParsableCommand {
2525
var count: Int?
2626

2727
mutating func run() throws {
28-
for _ in 0..<(count ?? Int.max) {
28+
for _ in 0..<(count ?? 2) {
2929
print(phrase)
3030
}
3131
}

Sources/ArgumentParser/Documentation.docc/Extensions/ParsableCommand.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct Repeat: ParsableCommand {
1212
var count: Int?
1313

1414
mutating func run() throws {
15-
let repeatCount = count ?? .max
15+
let repeatCount = count ?? 2
1616
for _ in 0..<repeatCount {
1717
print(phrase)
1818
}

Tests/ArgumentParserExampleTests/RepeatExampleTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ import ArgumentParserTestHelpers
1414

1515
final class RepeatExampleTests: XCTestCase {
1616
func testRepeat() throws {
17+
try AssertExecuteCommand(command: "repeat hello", expected: """
18+
hello
19+
hello
20+
""")
21+
}
22+
23+
func testRepeat_include_counter() throws {
24+
try AssertExecuteCommand(command: "repeat --include-counter hello", expected: """
25+
1: hello
26+
2: hello
27+
""")
28+
}
29+
30+
func testRepeat_Count() throws {
1731
try AssertExecuteCommand(command: "repeat hello --count 6", expected: """
1832
hello
1933
hello

0 commit comments

Comments
 (0)