Improved Bash class and removed Console.WriteLine statements
This commit is contained in:
parent
0a4c5ebb8d
commit
8fed922cfe
@ -6,6 +6,41 @@ namespace MicroForge.CLI;
|
||||
|
||||
public static class Bash
|
||||
{
|
||||
public static async Task RunAsync(params string[] script)
|
||||
{
|
||||
var info = new ProcessStartInfo
|
||||
{
|
||||
FileName = "bash",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
|
||||
using var process = Process.Start(info);
|
||||
|
||||
if (process is null)
|
||||
throw new NullReferenceException("Could not initialize bash process.");
|
||||
|
||||
process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);
|
||||
process.BeginOutputReadLine();
|
||||
process.ErrorDataReceived += (sender, args) => Console.WriteLine(args.Data);
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
await using var input = process.StandardInput;
|
||||
foreach (var line in script)
|
||||
await input.WriteLineAsync(line);
|
||||
|
||||
await input.FlushAsync();
|
||||
input.Close();
|
||||
|
||||
await process.WaitForExitAsync();
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
Console.WriteLine($"Process exited with status code {process.ExitCode}.");
|
||||
}
|
||||
|
||||
public static async Task ExecuteAsync(params string[] script)
|
||||
{
|
||||
var info = new ProcessStartInfo
|
||||
|
@ -26,7 +26,6 @@ public class OrmEnvInitializer : PythonSourceModifier
|
||||
public override object? VisitAssignment(PythonParser.AssignmentContext context)
|
||||
{
|
||||
var text = GetOriginalText(context);
|
||||
Console.WriteLine(text);
|
||||
|
||||
if (text == "target_metadata = None")
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ public partial class MicroForge
|
||||
|
||||
private async Task ExecuteAsync()
|
||||
{
|
||||
await Bash.ExecuteAsync([
|
||||
await Bash.RunAsync([
|
||||
"source .venv/bin/activate",
|
||||
"uvicorn main:app --reload"
|
||||
]);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import asyncio
|
||||
import asyncio
|
||||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import pool
|
||||
|
Loading…
Reference in New Issue
Block a user