Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Documentation/01 Getting Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Count: ParsableCommand {
@Argument()
var outputFile: String

func run() throws {
mutating func run() throws {
print("""
Counting words in '\(inputFile)' \
and writing the result into '\(outputFile)'.
Expand Down Expand Up @@ -91,7 +91,7 @@ struct Count: ParsableCommand {
@Option()
var outputFile: String

func run() throws {
mutating func run() throws {
print("""
Counting words in '\(inputFile)' \
and writing the result into '\(outputFile)'.
Expand Down Expand Up @@ -135,7 +135,7 @@ struct Count: ParsableCommand {
@Flag()
var verbose: Bool

func run() throws {
mutating func run() throws {
if verbose {
print("""
Counting words in '\(inputFile)' \
Expand Down Expand Up @@ -177,7 +177,7 @@ struct Count: ParsableCommand {
@Flag(name: .shortAndLong)
var verbose: Bool

func run() throws { ... }
mutating func run() throws { ... }
}
```

Expand Down Expand Up @@ -211,7 +211,7 @@ struct Count: ParsableCommand {
@Flag(name: .shortAndLong, help: "Print status updates while counting.")
var verbose: Bool

func run() throws { ... }
mutating func run() throws { ... }
}
```

Expand Down Expand Up @@ -246,7 +246,7 @@ struct Count: ParsableCommand {
@Flag(name: .shortAndLong, help: "Print status updates while counting.")
var verbose: Bool

func run() throws {
mutating func run() throws {
if verbose {
print("""
Counting words in '\(inputFile)' \
Expand Down
14 changes: 7 additions & 7 deletions Documentation/02 Arguments, Options, and Flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ enum ReleaseMode: String, ExpressibleByArgument {
struct Example: ParsableCommand {
@Option() var mode: ReleaseMode

func run() throws {
mutating func run() throws {
print(mode)
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ struct Example: ParsableCommand {
@Flag(default: nil, inversion: .prefixedEnableDisable)
var requiredElement: Bool

func run() throws {
mutating func run() throws {
print(index, requiredElement)
}
}
Expand Down Expand Up @@ -228,7 +228,7 @@ struct Example: ParsableCommand {

@Flag() var colors: [Color]

func run() throws {
mutating func run() throws {
print(cacheMethod)
print(colors)
}
Expand All @@ -252,7 +252,7 @@ struct Example: ParsableCommand {
@Flag(name: .shortAndLong)
var verbose: Int

func run() throws {
mutating func run() throws {
print("Verbosity level: \(verbose)")
}
}
Expand All @@ -279,7 +279,7 @@ struct Example: ParsableCommand {
@Option() var name: String
@Argument() var file: String?

func run() throws {
mutating func run() throws {
print("Verbose: \(verbose), name: \(name), file: \(file ?? "none")")
}
}
Expand Down Expand Up @@ -324,7 +324,7 @@ struct Example: ParsableCommand {
@Option() var file: [String]
@Flag() var verbose: Bool

func run() throws {
mutating func run() throws {
print("Verbose: \(verbose), files: \(file)")
}
}
Expand Down Expand Up @@ -374,7 +374,7 @@ struct Example: ParsableCommand {
@Flag() var verbose: Bool
@Argument() var files: [String]

func run() throws {
mutating func run() throws {
print("Verbose: \(verbose), files: \(files)")
}
}
Expand Down
8 changes: 4 additions & 4 deletions Documentation/03 Commands and Subcommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extension Math {
@OptionGroup()
var options: Math.Options

func run() {
mutating func run() {
let result = options.values.reduce(0, +)
print(format(result: result, usingHex: options.hexadecimalOutput))
}
Expand All @@ -85,7 +85,7 @@ extension Math {
@OptionGroup()
var options: Math.Options

func run() {
mutating func run() {
let result = options.values.reduce(1, *)
print(format(result: result, usingHex: options.hexadecimalOutput))
}
Expand Down Expand Up @@ -128,7 +128,7 @@ extension Math.Statistics {
func calculateMedian() -> Double { ... }
func calculateMode() -> [Double] { ... }

func run() {
mutating func run() {
switch kind {
case .mean:
print(calculateMean())
Expand All @@ -151,7 +151,7 @@ extension Math.Statistics {
@Argument(help: "A group of floating-point values to operate on.")
var values: [Double]

func run() {
mutating func run() {
if values.isEmpty {
print(0.0)
} else {
Expand Down
4 changes: 2 additions & 2 deletions Documentation/04 Customizing Help.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct Repeat: ParsableCommand {
@Argument(help: "The phrase to repeat.")
var phrase: String

func run() throws {
mutating func run() throws {
while true { print(phrase) }
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ struct Example: ParsableCommand {
@Option(name: .shortAndLong, help: "The number of history entries to show.")
var historyDepth: Int

func run() throws {
mutating func run() throws {
printHistory(depth: historyDepth)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Documentation/05 Validation and Errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Select: ParsableCommand {
}
}

func run() {
mutating func run() {
print(elements.shuffled().prefix(count).joined(separator: "\n"))
}
}
Expand Down Expand Up @@ -63,7 +63,7 @@ The `ValidationError` type is a special `ArgumentParser` error — a validation
struct LineCount: ParsableCommand {
@Argument() var file: String

func run() throws {
mutating func run() throws {
let contents = try String(contentsOfFile: file, encoding: .utf8)
let lines = contents.split(separator: "\n")
print(lines.count)
Expand Down Expand Up @@ -91,7 +91,7 @@ struct RuntimeError: Error, CustomStringConvertible {
struct Example: ParsableCommand {
@Argument() var inputFile: String

func run() throws {
mutating func run() throws {
if !ExampleCore.processFile(inputFile) {
// ExampleCore.processFile(_:) prints its own errors
// and returns `false` on failure.
Expand Down
4 changes: 2 additions & 2 deletions Documentation/06 Manual Parsing and Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ Let's see how this works by using the `Math` command and subcommands defined in

```swift
do {
let command = try Math.parseAsRoot()
var command = try Math.parseAsRoot()

switch command {
case let command as Math.Add:
case var command as Math.Add:
print("You chose to add \(command.options.values.count) values.")
command.run()
default:
Expand Down
8 changes: 4 additions & 4 deletions Examples/math/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extension Math {
@OptionGroup()
var options: Options

func run() {
mutating func run() {
let result = options.values.reduce(0, +)
print(format(result, usingHex: options.hexadecimalOutput))
}
Expand All @@ -70,7 +70,7 @@ extension Math {
@OptionGroup()
var options: Options

func run() {
mutating func run() {
let result = options.values.reduce(1, *)
print(format(result, usingHex: options.hexadecimalOutput))
}
Expand Down Expand Up @@ -145,7 +145,7 @@ extension Math.Statistics {
.map { k, _ in k }
}

func run() {
mutating func run() {
switch kind {
case .mean:
print(calculateMean())
Expand All @@ -168,7 +168,7 @@ extension Math.Statistics {
@Argument(help: "A group of floating-point values to operate on.")
var values: [Double]

func run() {
mutating func run() {
if values.isEmpty {
print(0.0)
} else {
Expand Down
2 changes: 1 addition & 1 deletion Examples/repeat/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Repeat: ParsableCommand {
@Argument(help: "The phrase to repeat.")
var phrase: String

func run() throws {
mutating func run() throws {
let repeatCount = count ?? .max

for i in 1...repeatCount {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Repeat: ParsableCommand {
@Argument(help: "The phrase to repeat.")
var phrase: String

func run() throws {
mutating func run() throws {
let repeatCount = count ?? .max

for i in 1...repeatCount {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ArgumentParser/Parsable Types/EnumerableFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/// struct Example: ParsableCommand {
/// @Flag() var sizes: [Size]
///
/// func run() {
/// mutating func run() {
/// print(sizes)
/// }
/// }
Expand Down
6 changes: 3 additions & 3 deletions Sources/ArgumentParser/Parsable Types/ParsableCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public protocol ParsableCommand: ParsableArguments {
/// application by calling the static `main()` method on the root type.
/// This method has a default implementation that prints help text
/// for this command.
func run() throws
mutating func run() throws
}

extension ParsableCommand {
Expand All @@ -41,7 +41,7 @@ extension ParsableCommand {
CommandConfiguration()
}

public func run() throws {
public mutating func run() throws {
throw CleanExit.helpRequest(self)
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ extension ParsableCommand {
/// `arguments` is `nil`, this uses the program's command-line arguments.
public static func main(_ arguments: [String]? = nil) -> Never {
do {
let command = try parseAsRoot(arguments)
var command = try parseAsRoot(arguments)
try command.run()
exit()
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ArgumentParser/Usage/HelpCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct HelpCommand: ParsableCommand {

init() {}

func run() throws {
mutating func run() throws {
throw CommandError(commandStack: commandStack, parserError: .helpRequested)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/ArgumentParserTestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public protocol TestableParsableCommand: ParsableCommand, TestableParsableArgume
}

public extension TestableParsableCommand {
func run() throws {
mutating func run() throws {
didRunExpectation.fulfill()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ extension RepeatingEndToEndTests {
struct PerformanceTest: ParsableCommand {
@Option(name: .short) var bundleIdentifiers: [String]

func run() throws { print(bundleIdentifiers) }
mutating func run() throws { print(bundleIdentifiers) }
}

fileprivate func argumentGenerator(_ count: Int) -> [String] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fileprivate struct Math: ParsableCommand {
@Argument(help: "The first operand")
var operands: [Int]

func run() {
mutating func run() {
XCTAssertEqual(operation, .multiply)
XCTAssertTrue(verbose)
XCTAssertEqual(operands, [5, 11])
Expand All @@ -136,7 +136,7 @@ fileprivate struct Math: ParsableCommand {

extension SubcommandEndToEndTests {
func testParsing_SingleCommand() throws {
let mathCommand = try Math.parseAsRoot(["--operation", "multiply", "-v", "5", "11"])
var mathCommand = try Math.parseAsRoot(["--operation", "multiply", "-v", "5", "11"])
XCTAssertFalse(mathDidRun)
try mathCommand.run()
XCTAssertTrue(mathDidRun)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension Package {
@Option(help: "Path to xcconfig file")
var xcconfigOverrides: String?

func run() {
mutating func run() {
print("Generating Xcode Project.......")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ParsableArgumentsValidationTests: XCTestCase {
case phrase
}

func run() throws {}
mutating func run() throws {}
}

private struct B: ParsableCommand {
Expand All @@ -36,7 +36,7 @@ final class ParsableArgumentsValidationTests: XCTestCase {
@Argument(help: "The phrase to repeat.")
var phrase: String

func run() throws {}
mutating func run() throws {}
}

private struct C: ParsableCommand {
Expand All @@ -50,7 +50,7 @@ final class ParsableArgumentsValidationTests: XCTestCase {
case phrase
}

func run() throws {}
mutating func run() throws {}
}

private struct D: ParsableArguments {
Expand Down
2 changes: 1 addition & 1 deletion Tools/changelog-authors/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct ChangelogAuthors: ParsableCommand {
return url
}

func run() throws {
mutating func run() throws {
let data = try Data(contentsOf: try comparisonURL())
let comparison = try JSONDecoder().decode(Comparison.self, from: data)
let authors = comparison.commits.map({ $0.author })
Expand Down