diff --git a/Examples/count-lines/CountLines.swift b/Examples/count-lines/CountLines.swift index 3289ef221..fae5f845e 100644 --- a/Examples/count-lines/CountLines.swift +++ b/Examples/count-lines/CountLines.swift @@ -10,7 +10,11 @@ //===----------------------------------------------------------------------===// import ArgumentParser +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @main @available(macOS 12, *) diff --git a/Plugins/GenerateManual/GenerateManualPluginError.swift b/Plugins/GenerateManual/GenerateManualPluginError.swift index 43138d2b7..1d6ea2123 100644 --- a/Plugins/GenerateManual/GenerateManualPluginError.swift +++ b/Plugins/GenerateManual/GenerateManualPluginError.swift @@ -8,8 +8,11 @@ // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// - +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import PackagePlugin enum GenerateManualPluginError: Error { diff --git a/Sources/ArgumentParser/Documentation.docc/Articles/GettingStarted.md b/Sources/ArgumentParser/Documentation.docc/Articles/GettingStarted.md index 136aca619..6f8a0364c 100644 --- a/Sources/ArgumentParser/Documentation.docc/Articles/GettingStarted.md +++ b/Sources/ArgumentParser/Documentation.docc/Articles/GettingStarted.md @@ -228,7 +228,11 @@ As promised, here's the complete `count` command, for your experimentation: ```swift import ArgumentParser +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @main struct Count: ParsableCommand { diff --git a/Sources/ArgumentParser/Documentation.docc/Extensions/AsyncParsableCommand.md b/Sources/ArgumentParser/Documentation.docc/Extensions/AsyncParsableCommand.md index f6a6238d8..0210ac3c5 100644 --- a/Sources/ArgumentParser/Documentation.docc/Extensions/AsyncParsableCommand.md +++ b/Sources/ArgumentParser/Documentation.docc/Extensions/AsyncParsableCommand.md @@ -9,7 +9,11 @@ To use `async`/`await` code in your commands' `run()` method implementations, fo The following example declares a `CountLines` command that uses Foundation's asynchronous `FileHandle.AsyncBytes` to read the lines from a file: ```swift +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @main struct CountLines: AsyncParsableCommand { diff --git a/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift b/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift index e1b562434..271510499 100644 --- a/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift +++ b/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift @@ -9,10 +9,15 @@ // //===----------------------------------------------------------------------===// -#if swift(>=5.11) +#if compiler(>=6.0) +#if canImport(FoundationEssentials) +internal import ArgumentParserToolInfo +internal import class FoundationEssentials.JSONEncoder +#else internal import ArgumentParserToolInfo internal import class Foundation.JSONEncoder -#elseif swift(>=5.10) +#endif +#elseif compiler(>=5.10) import ArgumentParserToolInfo import class Foundation.JSONEncoder #else diff --git a/Sources/ArgumentParser/Usage/MessageInfo.swift b/Sources/ArgumentParser/Usage/MessageInfo.swift index bb9a4ea1d..da39f1a9c 100644 --- a/Sources/ArgumentParser/Usage/MessageInfo.swift +++ b/Sources/ArgumentParser/Usage/MessageInfo.swift @@ -9,15 +9,16 @@ // //===----------------------------------------------------------------------===// -#if swift(>=5.11) +#if compiler(>=6.0) +#if canImport(FoundationEssentials) +internal import protocol FoundationEssentials.LocalizedError +#else internal import protocol Foundation.LocalizedError -internal import class Foundation.NSError -#elseif swift(>=5.10) +#endif +#elseif compiler(>=5.10) import protocol Foundation.LocalizedError -import class Foundation.NSError #else @_implementationOnly import protocol Foundation.LocalizedError -@_implementationOnly import class Foundation.NSError #endif enum MessageInfo { @@ -119,11 +120,7 @@ enum MessageInfo { case let error as LocalizedError where error.errorDescription != nil: self = .other(message: error.errorDescription!, exitCode: .failure) default: - if Swift.type(of: error) is NSError.Type { - self = .other(message: error.localizedDescription, exitCode: .failure) - } else { - self = .other(message: String(describing: error), exitCode: .failure) - } + self = .other(message: String(describing: error), exitCode: .failure) } } else if let parserError = parserError { let usage: String = { diff --git a/Sources/ArgumentParser/Usage/UsageGenerator.swift b/Sources/ArgumentParser/Usage/UsageGenerator.swift index e34b94ee6..c8397505d 100644 --- a/Sources/ArgumentParser/Usage/UsageGenerator.swift +++ b/Sources/ArgumentParser/Usage/UsageGenerator.swift @@ -9,9 +9,13 @@ // //===----------------------------------------------------------------------===// -#if swift(>=5.11) +#if compiler(>=6.0) +#if canImport(FoundationEssentials) +internal import protocol FoundationEssentials.LocalizedError +#else internal import protocol Foundation.LocalizedError -#elseif swift(>=5.10) +#endif +#elseif compiler(>=5.10) import protocol Foundation.LocalizedError #else @_implementationOnly import protocol Foundation.LocalizedError diff --git a/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift b/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift index fe1ebca6d..c4aeb7985 100644 --- a/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift +++ b/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift @@ -83,7 +83,7 @@ extension DumpHelpGenerationTests { var opt: Color? @Option(help: "An optional color with a default value.") - var optWithDefault: Color? = .yellow + var optWithDefault: Color = .yellow @Option(help: .init(discussion: "A preamble for the list of values in the discussion section.")) var extra: Color diff --git a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift index dc74ddee6..892babe69 100644 --- a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift +++ b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift @@ -16,7 +16,7 @@ import ArgumentParserTestHelpers final class HelpGenerationTests: XCTestCase { } -extension Foundation.URL: ArgumentParser.ExpressibleByArgument { +extension URL: ArgumentParser.ExpressibleByArgument { public init?(argument: String) { guard let url = URL(string: argument) else { return nil diff --git a/Tools/changelog-authors/ChangelogAuthors.swift b/Tools/changelog-authors/ChangelogAuthors.swift index 1ab3f6894..54e9dba08 100644 --- a/Tools/changelog-authors/ChangelogAuthors.swift +++ b/Tools/changelog-authors/ChangelogAuthors.swift @@ -12,7 +12,11 @@ #if os(macOS) import ArgumentParser +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // MARK: Command diff --git a/Tools/generate-manual/DSL/Document.swift b/Tools/generate-manual/DSL/Document.swift index 86c43aed0..7b6c66769 100644 --- a/Tools/generate-manual/DSL/Document.swift +++ b/Tools/generate-manual/DSL/Document.swift @@ -11,7 +11,11 @@ import ArgumentParser import ArgumentParserToolInfo +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif struct Document: MDocComponent { var multiPage: Bool diff --git a/Tools/generate-manual/DSL/Preamble.swift b/Tools/generate-manual/DSL/Preamble.swift index a75383c0b..96045ab73 100644 --- a/Tools/generate-manual/DSL/Preamble.swift +++ b/Tools/generate-manual/DSL/Preamble.swift @@ -11,7 +11,11 @@ import ArgumentParser import ArgumentParserToolInfo +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif struct Preamble: MDocComponent { var date: Date diff --git a/Tools/generate-manual/Extensions/Date+ExpressibleByArgument.swift b/Tools/generate-manual/Extensions/Date+ExpressibleByArgument.swift index 0d0f5ed08..6f3d96cb5 100644 --- a/Tools/generate-manual/Extensions/Date+ExpressibleByArgument.swift +++ b/Tools/generate-manual/Extensions/Date+ExpressibleByArgument.swift @@ -10,9 +10,13 @@ //===----------------------------------------------------------------------===// import ArgumentParser +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif -extension Foundation.Date: ArgumentParser.ExpressibleByArgument { +extension Date: ArgumentParser.ExpressibleByArgument { // parsed as `yyyy-mm-dd` public init?(argument: String) { // ensure the input argument is composed of exactly 3 components separated