Flag
public struct Flag : Hashable
Flag struct representing a flag
Example:
Create a flag with a default value
let flag = try! try! Flag(longName: "debug", shortName: "d", value: true, description: "Here is a desc")
Create a non required flag without value
let flag = try! Flag(longName: "debug", type: Int.self)
Create a required flag without value
let flag = try! Flag(longName: "debug", type: Int.self, required: true)
-
Flag long name. Such as
verbose
Must be non empty without spaces and special charactersDeclaration
Swift
public let longName: String
-
Flag short name. Should be one letter. Such as
v
Must be 1 alpha numeric characterDeclaration
Swift
public let shortName: String?
-
Set the flag to be inheritable An inheritable flag is valid for a command and all its subcommands
Declaration
Swift
public let inheritable: Bool
-
The flag description printed in the help beside the flag name
Declaration
Swift
public let description: String
-
Flag value type.
Declaration
Swift
public let type: FlagValue.Type
-
Set the flag to be required A required flag must be set in order for commands to be executed.
Declaration
Swift
public let required: Bool
-
Set the flag to allow multiple values A repeatable flag can be specified multiple times and will return an array of values.
Declaration
Swift
public var repeatable: Bool
-
Flag deprecation status.
Declaration
Swift
public var deprecationStatus: DeprecationStatus
-
Gets the flag hash value.
Declaration
Swift
public var hashValue: Int { get }
-
Creates a new flag
Discussion:
If the flag contains spaces, dashes and other special characters the command will exit printing the error
Example:
Create a flag with a default value
let flag = try! Flag(longName: "debug", shortName: "d", value: true, description: "Here is a desc")
Declaration
Swift
public init<T: FlagValue>(shortName: String? = nil, longName: String, value: T, description: String, inheritable: Bool = false)
Parameters
shortName
(Optional) Flag short name, the short name must be 1 alpha numeric character. Defaults to nil
longName
Flag long name, must be non empty without spaces or empty characters
value
Flag default value
description
Flag description to be shown when displaying command help
inheritable
(Optional)Flag inheritable status. Defaults to false
-
Creates a new flag
Discussion:
If the flag contains spaces, dashes and other special characters the command will exit printing the error
Example:
Create a flag with a default value
let flag = try! Flag(longName: "target", shortName: "t", values: "small", "fast", description: "Here is a desc")
Declaration
Swift
public init<T: FlagValue>(shortName: String? = nil, longName: String, values: [T], description: String, inheritable: Bool = false)
Parameters
shortName
(Optional) Flag short name, the short name must be 1 alpha numeric character. Defaults to nil
longName
Flag long name, must be non empty without spaces or empty characters
values
Flag default values
description
Flag description to be shown when displaying command help
inheritable
(Optional)Flag inheritable status. Defaults to false
-
Creates a new flag
Discussion:
If the flag contains spaces, dashes and other special characters the command will exit printing the error
Example:
Create a flag with a default value
let flag = try! Flag(longName: "target", shortName: "t", values: "small", "fast", description: "Here is a desc")
Declaration
Swift
public init<T: FlagValue>(shortName: String? = nil, longName: String, values: T..., description: String, inheritable: Bool = false)
Parameters
shortName
(Optional) Flag short name, the short name must be 1 alpha numeric character. Defaults to nil
longName
Flag long name, must be non empty without spaces or empty characters
values
Flag default values
description
Flag description to be shown when displaying command help
inheritable
(Optional)Flag inheritable status. Defaults to false
-
Creates a new flag
Discussion:
If the flag contains spaces, dashes and other special characters the command will exit printing the error
Example:
Create a flag with a default value
let flag = try! Flag(longName: "debug", type: Int.self, required: true)
Declaration
Swift
public init<T: FlagValue>(shortName: String? = nil, longName: String, type: T.Type, description: String, required: Bool = false, repeatable: Bool = false, inheritable: Bool = false)
Parameters
shortName
(Optional) Flag short name, the short name must be 1 alpha numeric character. Defaults to nil
longName
Flag long name, must be non empty without spaces or empty characters
type
Flag value type
description
Flag description to be shown when displaying command help
required
(Optional)Flag requirement status. Defaults to false
repeatable
(Optional)Flag may contain multiple values. Defaults to false
inheritable
(Optional)Flag inheritable status. Defaults to false
-
Creates a new flag
Discussion:
If the flag contains spaces, dashes and other special characters the command will exit printing the error
Example:
Create a flag with a default value
let flag = try! Flag(longName: "debug", type: Int.self, required: true)
Declaration
Swift
public init<T: FlagValue>(shortName: String? = nil, longName: String, type: [T].Type, description: String, required: Bool = false, inheritable: Bool = false)
Parameters
shortName
(Optional) Flag short name, the short name must be 1 alpha numeric character. Defaults to nil
longName
Flag long name, must be non empty without spaces or empty characters
type
Flag value type
description
Flag description to be shown when displaying command help
required
(Optional)Flag requirement status. Defaults to false
inheritable
(Optional)Flag inheritable status. Defaults to false