Functions

The following functions are available globally.

  • Presents a user with a menu of items to choose from

    Declaration

    Swift

    public func choose(prompt: String, choices: String...) -> String

    Parameters

    prompt

    The menu prompt message

    choices

    List of choices

    Return Value

    The user selected item

  • Presents a user with a menu of items to choose from

    Declaration

    Swift

    public func choose<T>(costumizationBlock: (ChooseSettings<T> -> Void)) -> T

    Parameters

    costumizationBlock

    Closure to be called with a ChooseSettings, changes to the settings are reflected to the prompt

    Return Value

    The user selected item

  • Presents a user with a menu of items to choose from

    Declaration

    Swift

    public func choose<T>(prompt: String, type: T.Type, costumizationBlock: (ChooseSettings<T> -> Void)) -> T

    Parameters

    prompt

    The menu prompt message

    type

    The value type to be expected from the user

    costumizationBlock

    Closure to be called with a ChooseSettings, changes to the settings are reflected to the prompt

    Return Value

    The user selected item

  • Presents a user with a menu of items to choose from

    Declaration

    Swift

    public func choose<T>(type: T.Type, costumizationBlock: (ChooseSettings<T> -> Void)) -> T

    Parameters

    type

    The value type to be expected from the user

    costumizationBlock

    Closure to be called with a ChooseSettings, changes to the settings are reflected to the prompt

    Return Value

    The user selected item

  • Displays a yes/no prompt to the user

    Declaration

    Swift

    public func agree(prompt: String) -> Bool

    Parameters

    prompt

    The prompt to display

    Return Value

    the user decision

  • Display a promt to the user

    Declaration

    Swift

    public func ask(prompt: String, customizationBlock: (AskSettings<String> -> Void)? = nil) -> String

    Parameters

    prompt

    The message to display

    customizationBlock

    The block to costumize the prompt before displaying

    Return Value

    The string enters from the user

  • Display a promt to the user

    • discussion: If the user enters a wrong type, ask will keep prompting until a correct value has been entered

    Declaration

    Swift

    public func ask<T: ArgConvertibleType>(prompt: String, type: T.Type, customizationBlock: (AskSettings<T> -> Void)? = nil) -> T

    Parameters

    prompt

    The message to display

    type

    The value type to be expected from the user

    customizationBlock

    The block to costumize the prompt before displaying

    Return Value

    The string casted to the type requested

  • Executes a command and captures its output

    Declaration

    Swift

    public func run(command: String, args: String...) -> RunResults

    Parameters

    command

    the command to execute

    args

    the parameters to pass to the command

    Return Value

    RunResults describing the command results

  • Executes a command and captures its output

    Declaration

    Swift

    public func run(command: String, argsString: String) -> RunResults

    Parameters

    command

    the command to execute

    argString

    the arguments passed as a single string

    Return Value

    RunResults describing the command results

  • Executes a command and captures its output

    Declaration

    Swift

    public func run(command: String, args: [String]) -> RunResults

    Parameters

    command

    the command to execute

    args

    the parameters to pass to the command

    Return Value

    RunResults describing the command results

  • Executes a command and captures its output

    Declaration

    Swift

    public func run(command: String, settingsBlock: (RunSettings -> Void)) -> RunResults

    Parameters

    command

    the command to execute

    settingsBlock

    block that receives the settings to costumize the behavior of run

    Return Value

    RunResults describing the command results

  • Executes a command and captures its output

    Declaration

    Swift

    public func run(command: String, args: [String], settings: (RunSettings -> Void)) -> RunResults

    Parameters

    command

    the command to execute

    args

    the parameters to pass to the command

    settingsBlock

    block that receives the settings to costumize the behavior of run

    Return Value

    RunResults describing the command results

  • Execute a command in interactive mode, output won’t be captured

    Declaration

    Swift

    public func runWithoutCapture(command: String) -> Int

    Parameters

    command

    the command to execute

    Return Value

    executed command exit code