ParsableArguments
A type that can be parsed from a program’s command-line arguments.
protocol ParsableArguments : Decodable
Browse conforming typesWhen you implement a ParsableArguments
type, all properties must be declared with one of the four property wrappers provided by the ArgumentParser
library.
Handling Validation
func validate(
) throws Validates the properties of the instance after parsing.
Parsing a Type
static func parse([String]?
) throws -> Self Parses a new instance of this type from command-line arguments.
static func parseOrExit([String]?
) -> Self Parses a new instance of this type from command-line arguments or exits with a relevant message.
Exiting a Program
static func exit(withError: Error?
) -> Never Terminates execution with a message and exit code that is appropriate for the given error.
Generating Help Text
static func helpMessage(includeHidden: Bool, columns: Int?
) -> String Returns the text of the help screen for this type.
Handling Errors
static func message(for: Error
) -> String Returns a brief message for the given error.
static func fullMessage(for: Error, columns: Int?
) -> String Returns a full message for the given error, including usage information, if appropriate.
static func exitCode(for: Error
) -> ExitCode Returns the exit code for the given error.
Generating Completion Scripts
static func completionScript(for: CompletionShell
) -> String Returns a shell completion script for the specified shell.
struct CompletionShell
A shell for which the parser can generate a completion script.
Infrequently Used APIs
init(
) Creates an instance of this parsable type using the definitions given by each property’s wrapper.