forked from F4NT0/dotnet-generator-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralMethods.csx
More file actions
47 lines (38 loc) · 1.27 KB
/
GeneralMethods.csx
File metadata and controls
47 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#r "System.Console"
#r "System.Diagnostics.Process"
using System;
using System.Diagnostics;
void PrintBox(string text1, params string[] text2)
{
int padding = 2;
string content = $"│ >_ {text1} {string.Join(" ", text2)} ";
int width = content.Length + padding;
string top = "╭" + new string('─', width - 2) + "╮";
string middle = content + new string(' ', width - content.Length - 1) + "│";
string bottom = "╰" + new string('─', width - 2) + "╯";
Console.WriteLine(top);
Console.WriteLine(middle);
Console.WriteLine(bottom);
}
void RunCommand(string name, params string[] args)
{
Console.WriteLine("\nRunning the following command:\n");
PrintBox(name, args);
var process = new Process();
process.StartInfo.FileName = name;
process.StartInfo.Arguments = string.Join(" ", args);
process.StartInfo.RedirectStandardOutput = false;
process.StartInfo.RedirectStandardError = false;
process.StartInfo.UseShellExecute = true;
try
{
process.Start();
process.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine($"\n \u001b[31m \u001b[0m Error running command: {name} {string.Join(" ", args)}");
Console.WriteLine($"{ex}");
Environment.Exit(1);
}
}