Created
January 18, 2019 10:11
-
-
Save MrBoog/f0d42122eb98e6ad457a6d709428a969 to your computer and use it in GitHub Desktop.
demo for scripting swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
import Foundation | |
func backup() { | |
let args = CommandLine.arguments | |
guard args.count > 1 else { | |
return print("Backup Failed! : \n Detail: Missing commit message whick should be surrounded by quotation mark.") | |
} | |
let arg = args[1] | |
shell("git", "pull") | |
shell("git", "commit", "-am", arg) | |
shell("git", "push", "origin", "HEAD:source") | |
} | |
@discardableResult | |
func shell(_ args: String...) -> (String?, Int32) { | |
let task = Process() | |
task.launchPath = "/usr/bin/env" | |
task.arguments = args | |
task.launch() | |
task.waitUntilExit() | |
return (nil, task.terminationStatus) | |
// let pipe = Pipe() | |
// task.standardOutput = pipe | |
// task.standardError = pipe | |
// let data = pipe.fileHandleForReading.readDataToEndOfFile() | |
// let output = String(data: data, encoding: .utf8) | |
// return (output, task.terminationStatus) | |
} | |
backup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment