0001    //
0002    //  Structure.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 StructureCommand
main.swift:20
    registry.register(StructureCommand())
: CommandType { 0015 let verb = "structure" 0016 let function = "Print Swift structure information as JSON" 0017 0018 func run(options: StructureOptions) -> Result<(), SourceKittenError> { 0019 if !options.file.isEmpty { 0020 if let file = File(path: options.file) { 0021 print(Structure(file: file)) 0022 return .Success() 0023 } 0024 return .Failure(.ReadFailed(path: options.file)) 0025 } 0026 if !options.text.isEmpty { 0027 print(Structure(file: File(contents: options.text))) 0028 return .Success() 0029 } 0030 return .Failure( 0031 .InvalidArgument(description: "either file or text must be set when calling structure") 0032 ) 0033 } 0034 } 0035 0036 struct StructureOptions
StructureCommand.swift:40
    static func create(file: String) -> (text: String) -> StructureOptions {
: OptionsType { 0037 let file: String 0038 let text: String 0039 0040 static func create(file: String) -> (text: String) -> StructureOptions { 0041 return { text in 0042 self.init(file: file, text: text) 0043 } 0044 } 0045 0046 static func evaluate(m: CommandMode) -> Result<StructureOptions, CommandantError<SourceKittenError>> { 0047 return create 0048 <*> m <| Option(key: "file", defaultValue: "", usage: "relative or absolute path of Swift file to parse") 0049 <*> m <| Option(key: "text", defaultValue: "", usage: "Swift code text to parse") 0050 } 0051 } 0052