Skip to content
This repository was archived by the owner on Mar 1, 2020. It is now read-only.

Commit ce6b1f5

Browse files
committed
Add --version and --help options
1 parent f70ee4d commit ce6b1f5

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

bin/querykit.swift

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import PathKit
55
import Stencil
66

77

8+
let version = "0.1.2"
9+
810
extension Path {
911
static var processPath:Path {
1012
if Process.arguments[0].componentsSeparatedByString(Path.separator).count > 1 {
@@ -148,36 +150,48 @@ func render(model:NSManagedObjectModel, destination:Path, templatePath:Path) {
148150
}
149151
}
150152

151-
func run() {
152-
let arguments = Process.arguments
153+
func generate(modelPath:Path, outputPath:Path) {
154+
let modelExtension = modelPath.`extension`
155+
let isDataModel = modelExtension == "xcdatamodel"
156+
let isDataModeld = modelExtension == "xcdatamodeld"
153157

154-
if arguments.count == 3 {
155-
let modelPath = Path(arguments[1])
156-
let outputPath = Path(arguments[2])
157-
let modelExtension = modelPath.`extension`
158-
let isDataModel = modelExtension == "xcdatamodel"
159-
let isDataModeld = modelExtension == "xcdatamodeld"
160-
161-
if isDataModel || isDataModeld {
162-
if modelPath.isReadable {
163-
let templatePath = Path.defaultTemplatePath
164-
if !templatePath.isReadable {
165-
print("Template '\(templatePath)' is not readable.")
166-
} else {
167-
let compiledModel = compileCoreDataModel(modelPath)
168-
let modelURL = NSURL(fileURLWithPath: compiledModel.description)
169-
let model = NSManagedObjectModel(contentsOfURL: modelURL)!
170-
render(model, destination: outputPath, templatePath: templatePath)
171-
}
158+
if isDataModel || isDataModeld {
159+
if modelPath.isReadable {
160+
let templatePath = Path.defaultTemplatePath
161+
if !templatePath.isReadable {
162+
print("Template '\(templatePath)' is not readable.")
172163
} else {
173-
print("'\(modelPath)' does not exist or is not readable.")
164+
let compiledModel = compileCoreDataModel(modelPath)
165+
let modelURL = NSURL(fileURLWithPath: compiledModel.description)
166+
let model = NSManagedObjectModel(contentsOfURL: modelURL)!
167+
render(model, destination: outputPath, templatePath: templatePath)
174168
}
175169
} else {
176-
print("'\(modelPath)' is not a Core Data model.")
170+
print("'\(modelPath)' does not exist or is not readable.")
177171
}
178172
} else {
179-
let processName = arguments[0]
180-
print("Usage: \(processName) <model> <output-directory>")
173+
print("'\(modelPath)' is not a Core Data model.")
174+
}
175+
}
176+
177+
func usage() {
178+
let processName = Process.arguments.first!
179+
print("Usage: \(processName) <model> <output-directory>")
180+
}
181+
182+
func run() {
183+
let arguments = Process.arguments
184+
185+
if arguments.contains("--help") {
186+
usage()
187+
} else if arguments.contains("--version") {
188+
print(version)
189+
} else if arguments.count != 3 {
190+
usage()
191+
} else {
192+
let modelPath = Path(arguments[1])
193+
let outputPath = Path(arguments[2])
194+
generate(modelPath, outputPath: outputPath)
181195
}
182196
}
183197

0 commit comments

Comments
 (0)