0001    //
0002    //  DocCommand.swift
0003    //  SourceKitten
0004    //
0005    //  Created by JP Simard on 2015-01-07.
0006    //  Copyright (c) 2015 SourceKitten. All rights reserved.
0007    //
0008    
0009    import Commandant
0010    import Foundation
0011    import Result
0012    import SourceKittenFramework
0013    
0014    struct DocCommand
main.swift:18
    registry.register(DocCommand())
: CommandType { 0015 let verb = "doc" 0016 let function = "Print Swift docs as JSON or Objective-C docs as XML" 0017 0018 func run(options: DocOptions) -> Result<(), SourceKittenError> { 0019 let args = Process.arguments 0020 if options.objc { 0021 return runObjC(options, args: args) 0022 } else if options.singleFile { 0023 return runSwiftSingleFile(args) 0024 } 0025 let moduleName: String? = options.moduleName.isEmpty ? nil : options.moduleName 0026 return runSwiftModule(moduleName, args: args) 0027 } 0028 0029 func runSwiftModule(moduleName: String?, args: [String]) -> Result<(), SourceKittenError> { 0030 let xcodeBuildArgumentsStart = (moduleName != nil) ? 4 : 2 0031 let xcodeBuildArguments = Array<String>(args[xcodeBuildArgumentsStart..<args.count]) 0032 let module = Module(xcodeBuildArguments: xcodeBuildArguments, name: moduleName) 0033 0034 if let docs = module?.docs { 0035 print(docs) 0036 return .Success() 0037 } 0038 return .Failure(.DocFailed) 0039 } 0040 0041 func runSwiftSingleFile(args: [String]) -> Result<(), SourceKittenError> { 0042 if args.count < 5 { 0043 return .Failure(.InvalidArgument(description: "at least 5 arguments are required when using `--single-file`")) 0044 } 0045 let sourcekitdArguments = Array<String>(args[4..<args.count]) 0046 if let file = File(path: args[3]), 0047 docs = SwiftDocs(file: file, arguments: sourcekitdArguments) { 0048 print(docs) 0049 return .Success() 0050 } 0051 return .Failure(.ReadFailed(path: args[3])) 0052 } 0053 0054 func runObjC(options: DocOptions, args: [String]) -> Result<(), SourceKittenError> { 0055 let translationUnit = ClangTranslationUnit(headerFiles: [args[3]], compilerArguments: Array<String>(args[4..<args.count])) 0056 print(translationUnit) 0057 return .Success() 0058 } 0059 } 0060 0061 struct DocOptions
DocCommand.swift:66
    static func create(singleFile: Bool) -> (moduleName: String) -> (objc: Bool) -> DocOptions {
: OptionsType { 0062 let singleFile: Bool 0063 let moduleName: String 0064 let objc: Bool 0065 0066 static func create(singleFile: Bool) -> (moduleName: String) -> (objc: Bool) -> DocOptions { 0067 return { moduleName in { objc in 0068 self.init(singleFile: singleFile, moduleName: moduleName, objc: objc) 0069 }} 0070 } 0071 0072 static func evaluate(m: CommandMode) -> Result<DocOptions, CommandantError<SourceKittenError>> { 0073 return create 0074 <*> m <| Option(key: "single-file", defaultValue: false, usage: "only document one file") 0075 <*> m <| Option(key: "module-name", defaultValue: "", usage: "name of module to document (can't be used with `--single-file` or `--objc`)") 0076 <*> m <| Option(key: "objc", defaultValue: false, usage: "document Objective-C headers") 0077 } 0078 } 0079