fix: fixed sonya not working properly with stdin #1
shell now calls standard system from stdlib.h from c works on macOS, needed to test on linux regex strings in VarRegex were refactored into RegexBuilder all tests passed.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import Foundation
|
||||
import sonyalib
|
||||
|
||||
@main
|
||||
@@ -12,18 +13,25 @@ struct sonya {
|
||||
break
|
||||
case .noSonyafile:
|
||||
print("sonya: no sonyafile found in current directory")
|
||||
exit(1)
|
||||
case .isEmpty:
|
||||
print("sonya: sonyafile is empty")
|
||||
exit(2)
|
||||
case .syntaxError:
|
||||
print("sonya: syntax error in sonyafile")
|
||||
exit(3)
|
||||
case .noSuchRecipe:
|
||||
print("sonya: no recipe named '\(recipe)'")
|
||||
exit(4)
|
||||
case .noSuchDependency:
|
||||
print("sonya: unknown dependency")
|
||||
exit(5)
|
||||
case .shellReturnedError:
|
||||
print("sonya: command failed")
|
||||
exit(6)
|
||||
case .noSuchVariable:
|
||||
print("sonya: undefined variable referenced in recipe '\(recipe)'")
|
||||
exit(7)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// swift-tools-version: 6.2
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
@@ -9,17 +7,20 @@ let package = Package(
|
||||
.macOS(.v13)
|
||||
],
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, making them visible to other packages.
|
||||
.library(
|
||||
name: "sonyalib",
|
||||
targets: ["sonyalib"]
|
||||
),
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package, defining a module or a test suite.
|
||||
// Targets can depend on other targets in this package and products from dependencies.
|
||||
.target(
|
||||
name: "sonyalib"
|
||||
name: "ShellHelper",
|
||||
path: "Sources/shellHelper",
|
||||
publicHeadersPath: "."
|
||||
),
|
||||
.target(
|
||||
name: "sonyalib",
|
||||
dependencies: ["ShellHelper"]
|
||||
),
|
||||
.testTarget(
|
||||
name: "sonyalibTests",
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// shell_helper.c
|
||||
// sonyalib
|
||||
//
|
||||
// Created by hwacha on 4/22/26.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "shell_helper.h"
|
||||
|
||||
int run_system(const char *cmd) {
|
||||
return system(cmd);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// shell_helper.h
|
||||
// sonyalib
|
||||
//
|
||||
// Created by hwacha on 4/22/26.
|
||||
//
|
||||
|
||||
int run_system(const char *cmd);
|
||||
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ShellHelper
|
||||
|
||||
func openSonyafile() -> String? {
|
||||
let fileManager = FileManager.default
|
||||
@@ -21,19 +22,5 @@ func openSonyafile() -> String? {
|
||||
|
||||
@discardableResult
|
||||
func shell(_ command: String) -> Int32 {
|
||||
let process = Process()
|
||||
let pipe = Pipe()
|
||||
|
||||
process.standardOutput = pipe
|
||||
process.standardError = pipe
|
||||
process.executableURL = URL(fileURLWithPath: "/bin/bash")
|
||||
process.arguments = ["-c", command]
|
||||
|
||||
try? process.run()
|
||||
process.waitUntilExit()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
FileHandle.standardOutput.write(data)
|
||||
|
||||
return process.terminationStatus
|
||||
return run_system(command)
|
||||
}
|
||||
|
||||
@@ -7,9 +7,18 @@
|
||||
|
||||
// TODO: args
|
||||
|
||||
nonisolated(unsafe) let varRegex = #/\$\(([^\s\n]*)\)/#
|
||||
import RegexBuilder
|
||||
|
||||
nonisolated(unsafe) let argRegex = #/\$(\d+)/#
|
||||
nonisolated(unsafe) let varRegex = Regex {
|
||||
"$("
|
||||
Capture(ZeroOrMore(CharacterClass(.whitespace, .newlineSequence).inverted))
|
||||
")"
|
||||
}
|
||||
|
||||
nonisolated(unsafe) let argRegex = Regex {
|
||||
"$"
|
||||
OneOrMore(.digit)
|
||||
}
|
||||
|
||||
func resolve(_ command: String, vars: [String: String]) -> String? {
|
||||
return resolveVars(command, vars: vars)
|
||||
|
||||
Reference in New Issue
Block a user