Scaffold project structure

This commit is contained in:
T. R. Bernstein
2026-03-11 16:09:09 +01:00
commit 1a7e5ca5de
8 changed files with 224 additions and 0 deletions

View 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]
)
}

View 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
}
}

View 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.")
}
}
}