Skip to content

Commit

Permalink
General refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Aug 24, 2020
1 parent 64c7a99 commit 28e0caa
Show file tree
Hide file tree
Showing 11 changed files with 936 additions and 923 deletions.
2 changes: 1 addition & 1 deletion PerformanceTests/PerformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class PerformanceTests: XCTestCase {
// }
// }
//
// // Not possible to run in dry mode because it won't werite to cache
// // Not possible to run in dry mode because it won't write to cache
// // TODO: find a better way to test this
// func testCachedFormatting() {
// CLI.print = { _, _ in }
Expand Down
14 changes: 8 additions & 6 deletions Sources/CommandLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import Foundation

/// Public interface for the SwiftFormat command-line functions
public struct CLI {
public enum CLI {}

public extension CLI {
/// Output type for printed content
public enum OutputType {
enum OutputType {
case info
case success
case error
Expand All @@ -44,23 +46,23 @@ public struct CLI {
}

/// Output handler - override this to intercept output from the CLI
public static var print: (String, OutputType) -> Void = { _, _ in
static var print: (String, OutputType) -> Void = { _, _ in
fatalError("No print hook set.")
}

/// Input handler - override this to inject input into the CLI
/// Injected lines should include the terminating newline character
public static var readLine: () -> String? = {
static var readLine: () -> String? = {
Swift.readLine(strippingNewline: false)
}

/// Run the CLI with the specified input arguments
public static func run(in directory: String, with args: [String] = CommandLine.arguments) -> ExitCode {
static func run(in directory: String, with args: [String] = CommandLine.arguments) -> ExitCode {
return processArguments(args, in: directory)
}

/// Run the CLI with the specified input string (this will be parsed into multiple arguments)
public static func run(in directory: String, with argumentString: String) -> ExitCode {
static func run(in directory: String, with argumentString: String) -> ExitCode {
return run(in: directory, with: parseArguments(argumentString))
}
}
Expand Down
237 changes: 109 additions & 128 deletions Sources/Formatter.swift

Large diffs are not rendered by default.

Loading

0 comments on commit 28e0caa

Please sign in to comment.