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
9 changes: 7 additions & 2 deletions Sources/ArgumentParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ add_library(ArgumentParser
"Parsable Types/EnumerableFlag.swift"
"Parsable Types/ExpressibleByArgument.swift"
"Parsable Types/ParsableArguments.swift"
"Parsable Types/ParsableArgumentsValidation.swift"
"Parsable Types/ParsableCommand.swift"

Parsing/ArgumentDecoder.swift
Expand All @@ -47,7 +46,13 @@ add_library(ArgumentParser
Utilities/Platform.swift
Utilities/SequenceExtensions.swift
Utilities/StringExtensions.swift
Utilities/Tree.swift)
Utilities/Tree.swift

Validators/CodingKeyValidator.swift
Validators/NonsenseFlagsValidator.swift
Validators/ParsableArgumentsValidation.swift
Validators/PositionalArgumentsValidator.swift
Validators/UniqueNamesValidator.swift)
# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(ArgumentParser PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public struct Argument<Value>:
case .value(let v):
return v
case .definition:
fatalError(directlyInitializedError)
configurationFailure(directlyInitializedError)
}
}
set {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ArgumentParser/Parsable Properties/Flag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public struct Flag<Value>: Decodable, ParsedWrapper {
case .value(let v):
return v
case .definition:
fatalError(directlyInitializedError)
configurationFailure(directlyInitializedError)
}
}
set {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ArgumentParser/Parsable Properties/Option.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public struct Option<Value>: Decodable, ParsedWrapper {
case .value(let v):
return v
case .definition:
fatalError(directlyInitializedError)
configurationFailure(directlyInitializedError)
}
}
set {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public struct OptionGroup<Value: ParsableArguments>: Decodable, ParsedWrapper {
case .value(let v):
return v
case .definition:
fatalError(directlyInitializedError)
configurationFailure(directlyInitializedError)
}
}
set {
Expand Down
20 changes: 15 additions & 5 deletions Sources/ArgumentParser/Parsable Types/ParsableArguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ extension ArgumentSet {
do {
try type._validate(parent: parent)
} catch {
assertionFailure("\(error)")
configurationFailure("\(error)")
}
#endif

Expand Down Expand Up @@ -321,11 +321,23 @@ extension ArgumentSet {
}
}

/// Prints the given message to standard error and exits with a failure code.
///
/// - Parameter message: The message to print to standard error. `message`
/// should be pre-wrapped, if desired.
func configurationFailure(_ message: String) -> Never {
var errorOut = Platform.standardError
print("\n", to: &errorOut)
print(String(repeating: "-", count: 70), to: &errorOut)
print(message, to: &errorOut)
print(String(repeating: "-", count: 70), to: &errorOut)
print("\n", to: &errorOut)
Platform.exit(Platform.exitCodeFailure)
}

/// The fatal error message to display when someone accesses a
/// `ParsableArguments` type after initializing it directly.
internal let directlyInitializedError = """

--------------------------------------------------------------------
Can't read a value from a parsable argument definition.

This error indicates that a property declared with an `@Argument`,
Expand All @@ -335,6 +347,4 @@ internal let directlyInitializedError = """
To get a valid value, either call one of the static parsing methods
(`parse`, `parseAsRoot`, or `main`) or define an initializer that
initializes _every_ property of your parsable type.
--------------------------------------------------------------------

"""
Loading