-
Notifications
You must be signed in to change notification settings - Fork 880
Expand file tree
/
Copy pathProjectCommand.swift
More file actions
55 lines (41 loc) · 1.66 KB
/
ProjectCommand.swift
File metadata and controls
55 lines (41 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import Foundation
import SwiftCLI
import ProjectSpec
import XcodeGenKit
import PathKit
import Core
import Version
class ProjectCommand: Command {
let version: Version
let name: String
let shortDescription: String
@Key("-s", "--spec", description: "The path to the project spec file. Defaults to project.yml")
var spec: Path?
@Key("-r", "--project-root", description: "The path to the project root directory. Defaults to the directory containing the project spec.")
var projectRoot: Path?
@Flag("-n", "--no-env", description: "Disable environment variable expansions")
var disableEnvExpansion: Bool
init(version: Version, name: String, shortDescription: String) {
self.version = version
self.name = name
self.shortDescription = shortDescription
}
func execute() throws {
let projectSpecPath = (spec ?? "project.yml").absolute()
if !projectSpecPath.exists {
throw GenerationError.missingProjectSpec(projectSpecPath)
}
let specLoader = SpecLoader(version: version)
let projects: [Project]
let variables: [String: String] = disableEnvExpansion ? [:] : ProcessInfo.processInfo.environment
do {
projects = try specLoader.loadProjects(path: projectSpecPath, projectRoot: projectRoot, variables: variables)
} catch {
throw GenerationError.projectSpecParsingError(error)
}
for project in projects {
try execute(specLoader: specLoader, projectSpecPath: projectSpecPath, project: project)
}
}
func execute(specLoader: SpecLoader, projectSpecPath: Path, project: Project) throws {}
}