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 characters

    Declaration

    Swift

    public let longName: String
  • Flag short name. Should be one letter. Such as v Must be 1 alpha numeric character

    Declaration

    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
  • Flag value. The value can be int, bool, string or any other type that implements FlagValue

    Declaration

    Swift

    public var value: FlagValue?
  • Flag deprecation status.

    Declaration

    Swift

    public var deprecationStatus = DeprecationStatus.notDeprecated
  • Gets the flag hash value.

    Declaration

    Swift

    public var hashValue: Int
  • Creats 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(shortName: String? = nil,
                  longName: String,
                  value: FlagValue,
                  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

  • Creats 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(shortName: String? = nil,
                  longName: String,
                  type: FlagValue.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