Skip to content

Commit

Permalink
cli interface with a generate command
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Saunders committed Jul 8, 2019
1 parent 666b7d6 commit 51c54bc
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ build:
swift build

run: build
.build/debug/cdd-swift Examples/Models.swift
.build/debug/cdd-swift generate

xcode:
rm -rf cdd-swift.xcodeproj/
Expand Down
26 changes: 22 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/yonaskolb/JSONUtilities.git",
"state": {
"branch": null,
"revision": "db238f4858ac2ac3fff228b5b71ce90488a6a9b3",
"version": "4.1.0"
"revision": "128d2ffc22467f69569ef8ff971683e2393191a0",
"version": "4.2.0"
}
},
{
Expand Down Expand Up @@ -37,13 +37,22 @@
"version": "0.9.0"
}
},
{
"package": "llbuild",
"repositoryURL": "https://github.com/apple/swift-llbuild.git",
"state": {
"branch": null,
"revision": "f1c9ad9a253cdf1aa89a7f5c99c30b4513b06ddb",
"version": "0.1.1"
}
},
{
"package": "SwiftPM",
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
"state": {
"branch": null,
"revision": "235aacc514cb81a6881364b0fedcb3dd083228f3",
"version": "0.3.0"
"revision": "8656a25cb906c1896339f950ac960ee1b4fe8034",
"version": "0.4.0"
}
},
{
Expand All @@ -55,6 +64,15 @@
"version": "0.50000.0"
}
},
{
"package": "SwiftCLI",
"repositoryURL": "https://github.com/jakeheis/SwiftCLI",
"state": {
"branch": null,
"revision": "ba2268e67c07b9f9cfbc0801385e6238b36255eb",
"version": "5.3.2"
}
},
{
"package": "Yams",
"repositoryURL": "https://github.com/jpsim/Yams.git",
Expand Down
10 changes: 3 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ let package = Package(
.executable(name: "cdd-swift", targets: ["cdd-swift"]),
],
dependencies: [
// .package(url: "https://github.com/yanagiba/swift-ast.git", from: "0.18.10")
.package(url: "https://github.com/apple/swift-package-manager.git", from: "0.3.0"),
.package(url: "https://github.com/apple/swift-syntax.git", .exact("0.50000.0")),
.package(url: "https://github.com/jpsim/Yams.git", from: "1.0.2"),
// .package(url: "https://github.com/yonaskolb/SwagGen.git", from: "4.0.0"),
// .package(url: "https://github.com/jakeheis/SwiftCLI", from: "5.0.0"),
.package(url: "https://github.com/kylef/PathKit.git", from: "0.9.0"),
.package(url: "https://github.com/yonaskolb/JSONUtilities.git", from: "4.1.0"),
.package(url: "https://github.com/onevcat/Rainbow", from: "3.0.0")
.package(url: "https://github.com/onevcat/Rainbow", from: "3.0.0"),
.package(url: "https://github.com/jakeheis/SwiftCLI", from: "5.0.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "cdd-swift",
dependencies: ["Utility", "SwiftSyntax", "Yams", "PathKit", "JSONUtilities", "Rainbow"]),
dependencies: ["SwiftSyntax", "Yams", "PathKit", "JSONUtilities", "Rainbow", "SwiftCLI"]),
]
)
18 changes: 18 additions & 0 deletions Sources/cdd-swift/Cli/Generate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Generate.swift
// Basic
//
// Created by Rob Saunders on 7/8/19.
//

import Foundation
import SwiftCLI

class GenerateCommand: Command {
func execute() throws {
print("hello")
}

let name = "generate"
let shortDescription = "Generates code ..."
}
10 changes: 10 additions & 0 deletions Sources/cdd-swift/main.swift → Sources/cdd-swift/Cli/main.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import SwiftSyntax
import SwiftCLI

let arguments = Array(CommandLine.arguments.dropFirst())
//let project = try! ProjectReader(path: arguments[0])
Expand All @@ -15,3 +16,12 @@ print(project.project)
//case .failure(let err):
// print("error: \(err)")
//}

CLI(
name: "cdd-swift",
version: "0.1.0",
description: "Compiler Driven Development: Swift Adaptor",
commands: [
GenerateCommand()
]
).goAndExit()
7 changes: 5 additions & 2 deletions Sources/cdd-swift/Project/ProjectReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ class ProjectReader {
self.openapiDoc = try readOpenApi(path)
print("read openapi.yml")

let files = ["\(self.path + MODELS_DIR)/API.swift"]
let files = [
"\(self.path + MODELS_DIR)/API.swift"
]
let settingsFile = "\(self.path)/Settings.swift"

self.project = ParseSource(files, settingsFile: settingsFile)
// self.project = ParseSource(files, settingsFile: settingsFile)
self.project = Project(models: [], routes: [])
}

func readProject() {
Expand Down
23 changes: 20 additions & 3 deletions Sources/cdd-swift/SourceParser/SourceParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,27 @@ func findProjectInfo(syntax: SourceFileSyntax) -> ProjectInfo {
return ProjectInfo(hostname: "blah")
}

func ParseSource(_ files: [String], settingsFile: String) -> Project {
func ParseSourceFiles(_ files: [String]) -> [Result<SourceFileSyntax, Swift.Error>] {
return files.map{ file in
fileToSyntax(file)
}
}

func ParseSource(_ files: [String], settingsFile: String) -> Result<Project, Swift.Error> {




var models: [Model] = []
var routes: [Route] = []

let res = fileToSyntax(settingsFile).map({ syntax in
return ParseVariables(syntax)
})

guard case .success = res else { return res.map({ _ in return Project(models: [], routes: [])}) }


switch fileToSyntax(settingsFile) {
case .success(let syntax):
print(ParseVariables(syntax))
Expand All @@ -60,9 +77,9 @@ func ParseSource(_ files: [String], settingsFile: String) -> Project {
}
}

return Project(
return Result.success(Project(
models: models,
routes: routes)
routes: routes))
}

func fileToSyntax(_ file: String) -> Result<SourceFileSyntax, Swift.Error> {
Expand Down

0 comments on commit 51c54bc

Please sign in to comment.