Skip to content

Instantly share code, notes, and snippets.

View lordcodes's full-sized avatar
⌨️
Coding

Andrew Lord lordcodes

⌨️
Coding
View GitHub Profile
@lordcodes
lordcodes / main.swift
Last active March 10, 2020 09:55
Code for the article "Manage automation tasks using Swift Package Manager"
extension Tasks {
struct Uninstall: ParsableCommand {
static var configuration = CommandConfiguration(
commandName: "uninstall",
abstract: "Uninstall Uploader and remove from system."
)
func run() throws {
try runShell("rm -f /usr/local/bin/uploader")
}
@lordcodes
lordcodes / main.swift
Created March 10, 2020 09:55
Code for the article "Manage automation tasks using Swift Package Manager"
extension Tasks {
struct Install: ParsableCommand {
static var configuration = CommandConfiguration(
commandName: "install",
abstract: "Install Uploader for running globally."
)
func run() throws {
try runShell("swift build -c release")
try runShell("install .build/release/uploader-cli /usr/local/bin/uploader")
@lordcodes
lordcodes / main.swift
Created March 10, 2020 09:54
Code for the article "Manage automation tasks using Swift Package Manager"
extension Tasks {
struct Linting: ParsableCommand {
static var configuration = CommandConfiguration(
commandName: "lint",
abstract: "Lint the Uploader codebase, such as static analysis."
)
func run() throws {
try runShell("swift run swiftformat . --lint", continueOnError: true)
try runShell("swift run swiftlint")
@lordcodes
lordcodes / Shell.swift
Created March 10, 2020 09:53
Code for the article "Manage automation tasks using Swift Package Manager"
func runShell(_ command: String, continueOnError: Bool = false) throws {
do {
try shellOut(
to: command,
outputHandle: .standardOutput,
errorHandle: .standardError
)
} catch {
if !continueOnError {
throw ShellError()
@lordcodes
lordcodes / main.swift
Created March 10, 2020 09:53
Code for the article "Manage automation tasks using Swift Package Manager"
struct Tasks: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "tasks",
abstract: "An automation task runner for Uploader.",
subcommands: [Linting.self, Install.self, Uninstall.self]
)
}
Tasks.main()
@lordcodes
lordcodes / Package.swift
Created March 10, 2020 09:52
Code for the article "Manage automation tasks using Swift Package Manager"
products: [
...
.executable(name: "task", targets: ["UploaderTasks"])
]
@lordcodes
lordcodes / Package.swift
Created March 10, 2020 09:52
Code for the article "Manage automation tasks using Swift Package Manager"
targets: [
...
.target(
name: "UploaderTasks",
dependencies: ["ArgumentParser", "ShellOut"]
)
]
@lordcodes
lordcodes / Package.swift
Created March 10, 2020 09:50
Code for the article "Manage automation tasks using Swift Package Manager"
let package = Package(
name: "Uploader",
products: [
.executable(name: "uploader-cli", targets: ["Uploader"])
],
dependencies: [
.package(
url: "https://github.com/realm/SwiftLint",
from: "0.39.1"
),
@lordcodes
lordcodes / OrderDetailActivity.kt
Created March 1, 2020 20:07
Code for the article: "The power of lazy properties in Kotlin"
class OrderDetailActivity : FragmentActivity() {
val orderId by lazy {
intent.getParcelableExtra<OrderId>(EXTRA_ORDER_ID)
}
}
@lordcodes
lordcodes / MessageActivity.kt
Created March 1, 2020 20:06
Code for the article: "The power of lazy properties in Kotlin"
private val messageId by lazy(LazyThreadSafetyMode.NONE) { createMessageId() }