Option Reference

enum OptionType

Indicates the type of the option.

intOption(Int)

An int

stringOption(String)

A string

notPresent

indicates the option wasn’t present. Typically used for optional options.

extension OptionType : ExpressibleByStringLiteral
init(unicodeScalarLiteral: UnicodeScalarLiteralType)
init(extendedGraphemeClusterLiteral: ExtendedGraphemeClusterLiteralType)
init(stringLiteral: StringLiteralType)
class DefaultOption : Option

An option on the command line (e.g., –something).

let defaultValue : OptionType?
let required : Bool
let longName : String
let shortHelp : String
let type : OptionType
init(longName: String, help: String, defaultValue: OptionType? = nil, required: Bool = true, type: OptionType = OptionType.stringOption(""))

Creates a new option.

Parameters:
  • longName – The long name for the option (e.g. –myLongName)
  • defaultValue – A default value for the option, if the user does not specify a value.
  • required – Whether a value for this option is required, or whether it is optional. Note that, if defaultValue != nil, using required: false is not sensible.
  • type – The type of option. Use OptionType.StringType(“”) to indicate we expect a String or OptionType.IntType(0) to indicate we expect an Int.
func parse(_: inout [String], accumulateResult: inout ParseResult)throws
class ChoiceOption : Option

An option that allows the user to pick from several choices (multiple-choice).

let defaultValue : OptionType?
let required : Bool = true
let longName : String
let shortHelp : String
let choices : [String]
func parse(_: inout [String], accumulateResult: inout ParseResult)throws
init(longName: String, shortHelp: String, choices: [String], defaultValue: OptionType? = nil)

Construct a new ChoiceOption.

Parameters:
  • longName – The long name of the option, e.g. –myLongName
  • shortHelp – A one-line help for the option
  • choices – An array of choice strings
  • defaultValue – A default value for the choice, allowing the user to omit the option.
Bug:

This constructor uses strings for choices due to 📡22393113

var usageHelp : String
var longHelp : String
class SecureOption : Option

An option for a secure field. This kind of option cannot be passed as a command line argument, since then it would be listed in your .bash_history . Provide the default value or the user will be interactively prompted.

let defaultValue : OptionType?
let required : Bool
let longName : String
let shortHelp : String
init(longName: String, help: String, defaultValue: OptionType? = nil, required: Bool = false)

Create a new SecureOption.

Parameters:
  • longName – The long name of the option, e.g. –myLongName
  • help – A one-line help for the option
  • defaultValue – Be aware that if you pass a default value here, the user will not be prompted. This is specific to SecureOption. While the DefaultOption`s are often overridden by the user, in the `SecureOption case, the defaultValue is often used in cases where we can’t prompt the user interactively, such as unit tests and build servers.
  • required – Whether the option is required. If defaultValue != nil, required: true is not sensible.
func parse(_: inout [String], accumulateResult: inout ParseResult)throws
protocol Option
var defaultValue : OptionType?

The default value for the option. Setting a default value means the user can omit specifying an explicit value.

var required : Bool

Whether the option is required. Note that, if defaultValue != nil , using required: false is not sensible.

var longName : String

The long name for the option.

var shortHelp : String

A one-line help for the option

var usageHelp : String

A usage string for the option. This is typically e.g. --option [option]

var longHelp : String

A more detailed help for the option. This might include information about default values, remarks, etc.

var type : OptionType

A prototype for what type this option will hold. The defualt is StringOption.

func parse(_: inout [String], accumulateResult: inout ParseResult)throws
extension Option
var usageHelp : String
var type : OptionType
var longHelp : String