Skip to content

Commit

Permalink
Enable custom SwiftPlate repo to be specified as command line argument
Browse files Browse the repository at this point in the history
With this change, a custom SwiftPlate repo (say, a local clone), can be used
to get the template when running SwiftPlate. This is useful both for development
of SwiftPlate, but also in case someone wants to supply their own template.

Usage:

```
$ swiftplate --repo /users/john/code/swiftplate 
```
  • Loading branch information
JohnSundell committed Jan 10, 2017
1 parent b678ac0 commit 14ea56d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct Arguments {
var authorEmail: String?
var githubURL: String?
var organizationName: String?
var repositoryURL: URL?

init(commandLineArguments arguments: [String]) {
for (index, argument) in arguments.enumerated() {
Expand All @@ -92,6 +93,10 @@ struct Arguments {
githubURL = arguments.element(after: index)
case "--organizationname":
organizationName = arguments.element(after: index)
case "--repo":
if let urlString = arguments.element(after: index) {
repositoryURL = URL(string: urlString)
}
default:
break
}
Expand Down Expand Up @@ -212,10 +217,10 @@ func askForDestination() -> String {
return fileManager.currentDirectoryPath
}

func performGitClone(path: String) throws {
func performGitClone(url: URL, path: String) throws {
let process = Process()
process.launchPath = "/bin/bash"
process.arguments = ["-c", "git clone https://github.com/JohnSundell/SwiftPlate.git '\(path)' -q"]
process.arguments = ["-c", "git clone \(url.absoluteString) '\(path)' -q"]
process.launch()
process.waitUntilExit()
}
Expand Down Expand Up @@ -279,7 +284,8 @@ do {
}

try performCommand(description: "Making a local clone of the SwiftPlate repo") {
try performGitClone(path: gitClonePath)
let repositoryURL = arguments.repositoryURL ?? URL(string: "https://github.com/JohnSundell/SwiftPlate.git")!
try performGitClone(url: repositoryURL, path: gitClonePath)
}

try performCommand(description: "Copying template folder") {
Expand Down

0 comments on commit 14ea56d

Please sign in to comment.