Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions Examples/count-lines/CountLines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
//===----------------------------------------------------------------------===//

import ArgumentParser
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

@main
@available(macOS 12, *)
Expand Down
5 changes: 4 additions & 1 deletion Plugins/GenerateManual/GenerateManualPluginError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Plugins/GenerateManual/PackagePlugin+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
//
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
import PackagePlugin

extension ArgumentExtractor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion Sources/ArgumentParser/Usage/DumpHelpGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
//
//===----------------------------------------------------------------------===//

#if swift(>=5.11)
#if swift(>=6.0)
#if canImport(FoundationEssentials)
internal import ArgumentParserToolInfo
internal import class FoundationEssentials.JSONEncoder
#else
internal import ArgumentParserToolInfo
internal import class Foundation.JSONEncoder
#endif
#elseif swift(>=5.10)
import ArgumentParserToolInfo
import class Foundation.JSONEncoder
Expand Down
7 changes: 6 additions & 1 deletion Sources/ArgumentParser/Usage/MessageInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
//
//===----------------------------------------------------------------------===//

#if swift(>=5.11)
#if swift(>=6.0)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment that Swift 6 language mode needs to be enabled for these guards to work (which it is not in Package.swift).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be addressed by using #if compiler instead, as in provided suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks @MaxDesiatov!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if swift(>=6.0)
#if compiler(>=6.0)

#if canImport(FoundationEssentials)
internal import protocol FoundationEssentials.LocalizedError
internal import class FoundationEssentials.NSError
#else
internal import protocol Foundation.LocalizedError
internal import class Foundation.NSError
#endif
#elseif swift(>=5.10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#elseif swift(>=5.10)
#elseif compiler(>=5.10)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this actually exposes an issue - NSError isn't part of Foundation Essentials. Are folks happy to remove that check?

import protocol Foundation.LocalizedError
import class Foundation.NSError
Expand Down
6 changes: 5 additions & 1 deletion Sources/ArgumentParser/Usage/UsageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
//
//===----------------------------------------------------------------------===//

#if swift(>=5.11)
#if swift(>=6.0)
#if canImport(FoundationEssentials)
internal import protocol FoundationEssentials.LocalizedError
#else
internal import protocol Foundation.LocalizedError
#endif
#elseif swift(>=5.10)
import protocol Foundation.LocalizedError
#else
Expand Down
2 changes: 1 addition & 1 deletion Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Tools/changelog-authors/ChangelogAuthors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#if os(macOS)

import ArgumentParser
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// MARK: Command

Expand Down
4 changes: 4 additions & 0 deletions Tools/generate-manual/DSL/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

import ArgumentParser
import ArgumentParserToolInfo
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

struct Document: MDocComponent {
var multiPage: Bool
Expand Down
4 changes: 4 additions & 0 deletions Tools/generate-manual/DSL/DocumentDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

import ArgumentParser
import ArgumentParserToolInfo
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

struct DocumentDate: MDocComponent {
private var month: String
Expand Down
4 changes: 4 additions & 0 deletions Tools/generate-manual/DSL/Preamble.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

import ArgumentParser
import ArgumentParserToolInfo
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

struct Preamble: MDocComponent {
var date: Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Tools/generate-manual/Extensions/Process+SimpleAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
//
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

enum SubprocessError: Swift.Error, LocalizedError, CustomStringConvertible {
case missingExecutable(url: URL)
Expand Down
4 changes: 4 additions & 0 deletions Tools/generate-manual/GenerateManual.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

import ArgumentParser
import ArgumentParserToolInfo
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

enum GenerateManualError: Error {
case failedToRunSubprocess(error: Error)
Expand Down