This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.swift
46 lines (34 loc) · 1.46 KB
/
main.swift
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
import Foundation
import CLInterface
final class Swiftc : CLInterface {
var description = "Swift compiler"
@Argument("--output", "-o", usage: "Write output to <file>")
var outputPath: String?
@Argument("-g", usage: "Emit debug info", default: false)
var debugMode: Bool
@Argument("--verboseness", "-v", usage: "How verbose do you want output to be?")
var verboseness: Int
@PositionalArgument(name: "files", usage: "Files that will be compiled")
var files: [String]
}
do {
let swiftc = Swiftc()
// runs successfully
// try swiftc.parseArguments(["-o", "hello", "-v", "9000", "-g", "main.swift", "Greeter.swift"])
// runs successfully; outputPath == nil
try swiftc.parseArguments(["-v", "9000", "-g", "main.swift", "Greeter.swift"])
// runs successfully; -g uses default value (false)
// try swiftc.parseArguments(["-o", "hello", "-v", "9000", "main.swift", "Greeter.swift"])
// missing --verboseness (-v); will throw an error
// try swiftc.parseArguments(["-o", "hello", "-g", "main.swift", "Greeter.swift"])
// try swiftc.parseArguments(["-h"])
// try swiftc.parseArguments(["--wrong"])
// try swiftc.parseArguments([])
print(swiftc.outputPath as Any) // optional, no default
print(swiftc.debugMode) // non-optional, default
print(swiftc.verboseness) // non-optional, no default
print(swiftc.files)
} catch {
print(error.localizedDescription)
exit(1)
}