0001    //
0002    //  main.swift
0003    //  SourceKitten
0004    //
0005    //  Created by JP Simard on 2015-01-03.
0006    //  Copyright (c) 2015 SourceKitten. All rights reserved.
0007    //
0008    
0009    import Darwin
0010    import Foundation
0011    import Commandant
0012    
0013    // `sourcekitd_set_notification_handler()` set the handler to be executed on main thread queue.
0014    // So, we vacate main thread to `dispatch_main()`.
0015    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
0016        let registry = CommandRegistry<SourceKittenError>()
0017        registry.register(CompleteCommand())
0018        registry.register(DocCommand())
0019        registry.register(SyntaxCommand())
0020        registry.register(StructureCommand())
0021        registry.register(VersionCommand())
0022    
0023        let helpCommand = HelpCommand(registry: registry)
0024        registry.register(helpCommand)
0025    
0026        registry.main(defaultVerb: "help") { error in
0027            fputs("\(error)\n", stderr)
0028        }
0029    }
0030    
0031    dispatch_main()
0032