0001    //
0002    //  Command.swift
0003    //  SwiftCLI
0004    //
0005    //  Created by Jake Heiser on 7/11/14.
0006    //  Copyright (c) 2014 jakeheis. All rights reserved.
0007    //
0008    
0009    // MARK: Protocols
0010    
0011    /// The base protocol for all commands
0012    public protocol CommandType
CLI.swift:17
    private static var commands: [CommandType] = []
CLI.swift:20
    public static var versionComand: CommandType? = VersionCommand()
CLI.swift:21
    public static var defaultCommand: CommandType = helpCommand!
CLI.swift:54
    public class func registerCommand(command: CommandType) {
CLI.swift:64
    public class func registerCommands(commands: [CommandType]) {
CLI.swift:130
    class private func routeCommand(arguments arguments: RawArguments) throws -> CommandType {
CLI.swift:144
    class private func setupOptionsAndArguments(command: CommandType, arguments: RawArguments) throws -> (execute: Bool, arguments: CommandArguments?) {
Command.swift:37
public protocol OptionCommandType: CommandType {
Command.swift:59
extension CommandType {
CommandMessageGenerator.swift:11
    class func generateUsageStatement(command command: CommandType, options: Options?) -> String {
CommandMessageGenerator.swift:40
    class func generateMisusedOptionsStatement(command command: CommandType, options: Options) -> String? {
HelpCommand.swift:9
public class HelpCommand: CommandType {
HelpCommand.swift:11
    var allCommands: [CommandType] = []
HelpCommand.swift:44
    func printCommand(command: CommandType) {
Router.swift:24
    private let commands: [CommandType]
Router.swift:26
    private let defaultCommand: CommandType
Router.swift:33
    init(commands: [CommandType], arguments: RawArguments, defaultCommand: CommandType, config: Config?) {
Router.swift:33
    init(commands: [CommandType], arguments: RawArguments, defaultCommand: CommandType, config: Config?) {
Router.swift:41
    func route() throws -> CommandType {
Router.swift:51
    private func findCommand() throws -> CommandType {
Router.swift:52
        var command: CommandType?
VersionCommand.swift:9
public class VersionCommand: CommandType {
{ 0013 0014 /// The name of the command; used to route arguments to commands 0015 var commandName
CommandMessageGenerator.swift:14
        if !command.commandName.isEmpty {
CommandMessageGenerator.swift:15
            message += " \(command.commandName)"
HelpCommand.swift:45
        let description = command.commandShortDescription.padFront(totalLength: 20 - command.commandName.characters.count)
HelpCommand.swift:46
        print("- \(command.commandName)\(description)")
Router.swift:67
            command = commands.filter { $0.commandName == commandSearchName }.first
: String { get } 0016 0017 // The argument signature of the command; used to map RawArguments to CommandArguments 0018 /// See the README for details on this 0019 var commandSignature
CLI.swift:165
        let commandSignature = CommandSignature(command.commandSignature)
CommandMessageGenerator.swift:18
        if !command.commandSignature.isEmpty {
CommandMessageGenerator.swift:19
            message += " \(command.commandSignature)"
: String { get } 0020 0021 /// A short description of the command; printed in the command's usage statement 0022 var commandShortDescription
HelpCommand.swift:45
        let description = command.commandShortDescription.padFront(totalLength: 20 - command.commandName.characters.count)
: String { get } 0023 0024 /// An optional flag shorcut for the command; e.g. "-h" for the HelpCommand. Default's to nil. 0025 var commandShortcut
Router.swift:59
            if let shortcutCommand = commands.filter({ $0.commandShortcut == commandSearchName }).first
: String? { get } 0026 0027 /** 0028 The actual execution block of the command 0029 0030 - Parameter arguments: the parsed arguments 0031 */ 0032 func execute
CLI.swift:113
                try command.execute(arguments)
(arguments: CommandArguments) throws 0033 0034 } 0035 0036 /// An expansion of CommandType to provide for option handling 0037 public protocol OptionCommandType
CLI.swift:145
        if let optionCommand = command as? OptionCommandType {
Command.swift:65
extension OptionCommandType {
Command.swift:77
extension OptionCommandType {
CommandMessageGenerator.swift:41
        guard let optionsCommand = command as? OptionCommandType else {
LightweightCommand.swift:11
public class LightweightCommand: OptionCommandType {
: CommandType { 0038 0039 /// Whether the command should fail if passed unrecognized options. Default is true. 0040 var failOnUnrecognizedOptions
CLI.swift:159
                if optionCommand.failOnUnrecognizedOptions {
: Bool { get } 0041 0042 /// The output behavior of the command when passed unrecognized options. Default is .PrintAll 0043 var unrecognizedOptionsPrintingBehavior
CommandMessageGenerator.swift:45
        switch optionsCommand.unrecognizedOptionsPrintingBehavior {
: UnrecognizedOptionsPrintingBehavior { get } 0044 0045 /// Whether help for the command should be shown when -h is passed. Default is true. 0046 var helpOnHFlag
Command.swift:82
        if helpOnHFlag {
: Bool { get } 0047 0048 /** 0049 Where the command should configure all possible Options for the command 0050 0051 - Parameter options: the instance of Options which should be set up 0052 */ 0053 func setupOptions
Command.swift:80
        setupOptions(options)
(options: Options) 0054 0055 } 0056 0057 // MARK: Default implementations 0058 0059 extension CommandType { 0060 0061 public var commandShortcut: String? { return nil } 0062 0063 } 0064 0065 extension OptionCommandType { 0066 0067 public var failOnUnrecognizedOptions: Bool { return true } 0068 0069 public var unrecognizedOptionsPrintingBehavior: UnrecognizedOptionsPrintingBehavior { return .PrintAll } 0070 0071 public var helpOnHFlag: Bool { return true } 0072 0073 } 0074 0075 // MARK: Additional functionality 0076 0077 extension OptionCommandType { 0078 0079 func internalSetupOptions
CLI.swift:148
            optionCommand.internalSetupOptions(options)
(options: Options) { 0080 setupOptions(options) 0081 0082 if helpOnHFlag { 0083 let helpFlags = ["-h", "--help"] 0084 0085 options.onFlags(helpFlags, usage: "Show help information for this command") {(flag) in 0086 print(CommandMessageGenerator.generateUsageStatement(command: self, options: options)) 0087 } 0088 0089 options.exitEarlyOptions += helpFlags 0090 } 0091 } 0092 0093 } 0094 0095 // MARK: Enums 0096 0097 public enum UnrecognizedOptionsPrintingBehavior
ChainableCommand.swift:37
    public func withUnrecognizedOptionsPrintingBehavior(behavior: UnrecognizedOptionsPrintingBehavior) -> ChainableCommand {
Command.swift:43
    var unrecognizedOptionsPrintingBehavior: UnrecognizedOptionsPrintingBehavior { get }
Command.swift:69
    public var unrecognizedOptionsPrintingBehavior: UnrecognizedOptionsPrintingBehavior { return .PrintAll }
LightweightCommand.swift:19
    public var unrecognizedOptionsPrintingBehavior: UnrecognizedOptionsPrintingBehavior = .PrintAll
{ 0098 case PrintNone
CommandMessageGenerator.swift:46
        case .PrintNone:
0099 case PrintOnlyUnrecognizedOptions
CommandMessageGenerator.swift:50
        case .PrintOnlyUnrecognizedOptions:
0100 case PrintOnlyUsage
CommandMessageGenerator.swift:48
        case .PrintOnlyUsage:
0101 case PrintAll
Command.swift:69
    public var unrecognizedOptionsPrintingBehavior: UnrecognizedOptionsPrintingBehavior { return .PrintAll }
CommandMessageGenerator.swift:52
        case .PrintAll:
LightweightCommand.swift:19
    public var unrecognizedOptionsPrintingBehavior: UnrecognizedOptionsPrintingBehavior = .PrintAll
0102 } 0103