enums / SwiftyScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SwiftyScript

Talk to terminal.

Usage

0x01

// Use String
"echo Hello World".runAsBash()

0x02

// Run Other Progress
"""
echo 'import Foundation\nprint("Hello World From Swift")' > main.swift
swiftc main.swift
./main
""".runAsBash()

0x03

// Get Infomation From Command
let swiftTarget = "swift --version".runAsBash(output: .log).log.components(separatedBy: "\n")[1]
print("\(swiftTarget)")

0x04

// Build Project
let projects: [(name: String, buildTime: TimeInterval)] = [
    ("Project A", 2.0),
    ("Project B", 0.5),
    ("Project C", 0.1),
    ("Project D", 0.2),
    ("Project E", 2.5),
]

[
    "echo 'Building...'",
    projects.map { (name, time) in
    """
    echo '> Building \(name)...'
    echo 'runing xcbuild...'
    # do some job here
    sleep \(time)
    """
    }.joinedScript(),
    "echo 'Done.'",
]
.joinedScript()
.runAsBash(name: "Build Project", printTaskInfo: true)

0x05

// Use Task
Task.init(language: .Bash, content: "echo Bye").run()

About

License:Apache License 2.0


Languages

Language:Swift 99.3%Language:Shell 0.7%