-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathMain.swift
27 lines (23 loc) · 922 Bytes
/
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
import Foundation
@main
public struct Main {
public static func main() throws {
guard CommandLine.argc >= 2 else {
print("usage: mygit <command> [<args>...]")
return
}
let command = CommandLine.arguments[1]
switch command {
case "init":
let fileManager = FileManager.default
try fileManager.createDirectory(atPath: ".git", withIntermediateDirectories: false)
try fileManager.createDirectory(atPath: ".git/objects", withIntermediateDirectories: false)
try fileManager.createDirectory(atPath: ".git/refs", withIntermediateDirectories: false)
fileManager.createFile(atPath: ".git/HEAD", contents: "ref: refs/heads/master\n".data(using: .utf8))
print("Initialized git directory")
default:
print("Unknown command \(command)")
return
}
}
}