@@ -8,36 +8,76 @@
9import Foundation
9import Foundation
11−//let directory = "/Users/ilya/Developer/Dotrix/Dotrix/"
12−//let output = "/Users/ilya/Desktop/foo.tex"
14let args = Array(CommandLine.arguments.dropFirst())
11let args = Array(CommandLine.arguments.dropFirst())
15−let temp = FileManager.default.temporaryDirectory.appendingPathComponent("SourceDocsSwift/build\(Date().timeIntervalSince1970)")
12+//let temp = FileManager.default.temporaryDirectory.appendingPathComponent("SourceDocsSwift/build\(Date().timeIntervalSince1970)", isDirectory: true)
19var output = "docs.tex"
14var output = "docs.tex"
20var directory: String?
15var directory: String?
16+var style: TeXer.TexType = .laTeX(2)
23while i < args.count {
19while i < args.count {
24 switch args[i] {
20 switch args[i] {
25− case "-o":
21+ case "-o", "--output":
26 if i + 1 < args.count {
22 if i + 1 < args.count {
28 output = args[i]
24 output = args[i]
30− case "-i":
26+ case "-i", "--input":
31 if i + 1 < args.count {
27 if i + 1 < args.count {
33 directory = args[i]
29 directory = args[i]
31+ case "-s", "--style":
32+ if i + 1 < args.count {
34+ switch args[i].lowercased() {
35+ case "latex", "xetex", "tex":
36+ style = .laTeX(style.levelOffset)
37+ case "tech", "techdoc", "techdocs":
38+ style = .techDoc(style.levelOffset)
41+ That is not a valid style.
50+ case "-l", "--level":
51+ if i + 1 < args.count {
53+ guard let l = Int(args[i]) else {
55+ That is not a valid int.
61+ Level must be greater or equal to 1.
65+ style.levelOffset = l
73+var outputIsDirectory: ObjCBool = false
75+FileManager.default.fileExists(atPath: output, isDirectory: &outputIsDirectory)
77+if outputIsDirectory.boolValue {
78+ output.append("/docs.tex")
41let decoder = JSONDecoder()
81let decoder = JSONDecoder()
43guard let xcbTagetData = Shell.launch(executable: "/usr/bin/xcodebuild", arguments: ["-list", "-json"], launchDirectory: directory) else {
83guard let xcbTagetData = Shell.launch(executable: "/usr/bin/xcodebuild", arguments: ["-list", "-json"], launchDirectory: directory) else {
@@ -59,8 +99,8 @@ let targets = xcbResponse.targets
59var files: [String: [Object]] = [:]
99var files: [String: [Object]] = [:]
61for target in targets {
101for target in targets {
62− try? FileManager.default.removeItem(at: temp)
102+// try? FileManager.default.removeItem(at: temp)
63− guard let skResponseData = Shell.launch(executable: "/usr/local/bin/sourcekitten", arguments: ["doc", "--", "-target", target, "CONFIGURATION_BUILD_DIR=\(temp)"], launchDirectory: directory) else {
103+ guard let skResponseData = Shell.launch(executable: "/usr/local/bin/sourcekitten", arguments: ["doc", "--", "-target", target], launchDirectory: directory) else {
64 print("""
104 print("""
65 Make sure sourcekitten is installed
105 Make sure sourcekitten is installed
@@ -80,9 +120,15 @@ for target in targets {
83−let tex = TeXer.convert(objects: files.flatMap {$0.value})
123+let tex = TeXer.convert(objects: files.flatMap {$0.value}, with: style)
85−try? tex.write(toFile: output, atomically: true, encoding: .utf8)
125+ try tex.write(toFile: output, atomically: true, encoding: .utf8)
128+ There was an error writing the outuput file.