update migrate command

This commit is contained in:
yonaskolb 2022-01-05 14:08:54 +11:00
parent 4691c4e577
commit da7eabf148

View File

@ -8,25 +8,21 @@ import Yams
class MigrateCommand: Command { class MigrateCommand: Command {
let name: String = "migrate" let name: String = "migrate"
let shortDescription: String = "Migrates an Xcode project to an XcodeGen project spec"
let projectFile = Key<Path>("-p", "--project", description: "The path to the project file") @Param
var projectPath: Path
let spec = Key<Path>( @Key("-s", "--spec", description: "The path to the generated project spec. Defaults to project.yml in the same directory as the project")
"-s", var spec: Path?
"--spec",
description: "The path to the project spec file should be generated. Defaults to project.yml"
)
func execute() throws { func execute() throws {
guard let file = projectFile.value else { let xcodeProj = try XcodeProj(path: projectPath)
return let project = try generateSpec(xcodeProj: xcodeProj, projectDirectory: projectPath.parent())
}
let xcodeProj = try XcodeProj(path: file)
let project = try generateSpec(xcodeProj: xcodeProj, projectDirectory: file.parent())
let projectDict = project.toJSONDictionary().removeEmpty() let projectDict = project.toJSONDictionary().removeEmpty()
let encodedYAML = try Yams.dump(object: projectDict) let encodedYAML = try Yams.dump(object: projectDict)
let defaultOutPath = file.parent() + "project.yml" let defaultOutPath = projectPath.parent() + "project.yml"
let outPath = spec.value ?? defaultOutPath let outPath = spec ?? defaultOutPath
try encodedYAML.write(toFile: outPath.string, atomically: true, encoding: .utf8) try encodedYAML.write(toFile: outPath.string, atomically: true, encoding: .utf8)
} }
} }