Scaffold project structure
This commit is contained in:
2
Sources/Inotify/Inotify.swift
Normal file
2
Sources/Inotify/Inotify.swift
Normal file
@@ -0,0 +1,2 @@
|
||||
actor Inotify {
|
||||
}
|
||||
9
Sources/TaskCLI/Command.swift
Normal file
9
Sources/TaskCLI/Command.swift
Normal file
@@ -0,0 +1,9 @@
|
||||
import ArgumentParser
|
||||
|
||||
@main
|
||||
struct Command: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
abstract: "Project tasks of Astzweig's Swift Inotify project.",
|
||||
subcommands: [TestCommand.self]
|
||||
)
|
||||
}
|
||||
25
Sources/TaskCLI/Global Options.swift
Normal file
25
Sources/TaskCLI/Global Options.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
import ArgumentParser
|
||||
import Logging
|
||||
|
||||
struct GlobalOptions: ParsableArguments {
|
||||
@Flag(
|
||||
name: .short,
|
||||
help: "Increase logging verbosity. Use -v, -vv, or -vvv."
|
||||
)
|
||||
var verbose: Int
|
||||
|
||||
var logLevel: Logger.Level {
|
||||
switch verbose {
|
||||
case 0: return .notice
|
||||
case 1: return .info
|
||||
case 2: return .debug
|
||||
default: return .trace
|
||||
}
|
||||
}
|
||||
|
||||
func makeLogger(labeled label: String) -> Logger {
|
||||
var logger = Logger(label: label)
|
||||
logger.logLevel = logLevel
|
||||
return logger
|
||||
}
|
||||
}
|
||||
45
Sources/TaskCLI/Test Command.swift
Normal file
45
Sources/TaskCLI/Test Command.swift
Normal file
@@ -0,0 +1,45 @@
|
||||
import ArgumentParser
|
||||
import AsyncAlgorithms
|
||||
import Foundation
|
||||
import Subprocess
|
||||
import Noora
|
||||
|
||||
struct TestCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "test",
|
||||
abstract: "Run swift test in a linux container.",
|
||||
aliases: ["t"],
|
||||
)
|
||||
|
||||
@OptionGroup var global: GlobalOptions
|
||||
|
||||
// MARK: - Run
|
||||
|
||||
func run() async throws {
|
||||
let noora = Noora()
|
||||
let logger = global.makeLogger(labeled: "swift-inotify.cli.task.test")
|
||||
let currentDirectory = FileManager.default.currentDirectoryPath
|
||||
|
||||
noora.info("Running tests on Linux.")
|
||||
logger.debug("Current directory", metadata: ["current-directory": "\(currentDirectory)"])
|
||||
async let monitorResult = Subprocess.run(
|
||||
.name("docker"),
|
||||
arguments: ["run", "-v", "\(currentDirectory):/code", "--platform", "linux/arm64", "-w", "/code", "swift:latest", "swift", "test"],
|
||||
preferredBufferSize: 10,
|
||||
) { execution, standardInput, standardOutput, standardError in
|
||||
print("")
|
||||
let stdout = standardOutput.lines()
|
||||
let stderr = standardError.lines()
|
||||
for try await line in merge(stdout, stderr) {
|
||||
noora.passthrough("\(line)")
|
||||
}
|
||||
print("")
|
||||
}
|
||||
|
||||
if (try await monitorResult.terminationStatus.isSuccess) {
|
||||
noora.success("All tests completed successfully.")
|
||||
} else {
|
||||
noora.error("Not all tests completed successfully.")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user