Skip to content
This repository was archived by the owner on Jan 26, 2025. It is now read-only.

Commit a28d22e

Browse files
committed
better CLI
1 parent 14512f5 commit a28d22e

File tree

3 files changed

+73
-12
lines changed

3 files changed

+73
-12
lines changed

AutomataProcessor/AutomataProcessor.csproj

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -10,4 +10,8 @@
1010
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
1111
</PropertyGroup>
1212

13+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
14+
<DebugType>none</DebugType>
15+
</PropertyGroup>
16+
1317
</Project>

AutomataProcessor/Program.cs

+67-10
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,80 @@ namespace AutomataProcessor
88
{
99
static class Program
1010
{
11+
private static void PrintHelp()
12+
{
13+
Console.WriteLine("General Usage:\n amta file_name [--lib lib_folder] [--debug] [--max_while_loops N]\n\nfile_name is the file which will be interpreted.\nThe function called when running is !main\n\n--lib lib_folder - specify another lib folder.\nDefault: ./lib\n\n--debug - print debug messages from AutoMaTA\n\n--max_while_loops N - specify maximum number of times a while block can run.\nIf you want to disable the limit, use -1\nDefault: 10000\n\namta --help");
14+
}
15+
1116
public static void Main(string[] args)
1217
{
13-
Logger.Print("Automata Processor\nMade by devilexe");
14-
Logger.Debug(Directory.GetCurrentDirectory());
18+
Logger.Print("Automata Processor\nMade by devilexe\n\n");
19+
20+
if (args.Length == 0)
21+
{
22+
PrintHelp();
23+
return;
24+
}
25+
26+
string lib_folder = Path.Combine(Directory.GetCurrentDirectory(), "lib");
27+
string? amta_file = null;
28+
for(int i = 0; i < args.Length; ++i)
29+
{
30+
if (args[i].StartsWith("--"))
31+
{
32+
switch (args[i])
33+
{
34+
case "--help":
35+
PrintHelp();
36+
return;
37+
case "--lib":
38+
lib_folder = args[i + 1];
39+
++i;
40+
break;
41+
case "--debug":
42+
Config.PrintDebugMessages = true;
43+
break;
44+
case "--max_while_loops":
45+
if (int.TryParse(args[i + 1], out int N))
46+
{
47+
if (N == -1)
48+
Config.MaxWhileLoops = int.MaxValue; // disable while limit
49+
else
50+
Config.MaxWhileLoops = N;
51+
}
52+
else
53+
{
54+
Console.WriteLine("Invalid max_while_loops parameter: " + args[i + 1]);
55+
return;
56+
}
57+
break;
58+
}
59+
}
60+
else if(i == 0)
61+
amta_file = args[i];
62+
}
63+
if(amta_file == null)
64+
{
65+
PrintHelp();
66+
return;
67+
}
68+
if(!File.Exists(amta_file))
69+
{
70+
Console.WriteLine("File doesn't exist: " + amta_file + "\n\nPlease use \"amta --help\" for see a help page");
71+
return;
72+
}
1573

1674
// load libraries
17-
foreach (var file in Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "lib")))
75+
foreach (var file in Directory.GetFiles(lib_folder))
1876
{
1977
if (file.EndsWith(".amtascript"))
2078
{
2179
LibraryData.libs.Add(Path.GetFileNameWithoutExtension(file), () => File.ReadAllText(file));
2280
}
2381
}
2482

25-
Config.MaxWhileLoops = int.MaxValue; // disable while limit
26-
Config.PrintDebugMessages = true;
27-
ProgramScope scope = new ProgramScope("Automata CLI");
28-
string amtascript = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "script.amtascript"));
83+
ProgramScope scope = new ProgramScope("AutoMaTA Processor");
84+
string amtascript = File.ReadAllText(amta_file);
2985
Logger.Debug("Loaded script:\n" + amtascript);
3086

3187
// register print function
@@ -35,18 +91,19 @@ public static void Main(string[] args)
3591
var_str = scope.GetVariable("print_0");
3692
if (var_str == null)
3793
{
38-
Logger.Print("[Automoata] Print function called, but no parameter provided. Use $print_string of $print_0");
94+
Logger.Print("[AutoMaTA] Print function called, but no parameter provided. Use $print_string or $print_0");
3995
return;
4096
}
4197
if (var_str.var_type != Variable.VariableType.String)
4298
{
43-
Logger.Print("[Automata] Print function called, but argument was not string");
99+
Logger.Print("[AutoMaTA] Print function called, but argument was not string");
44100
return;
45101
}
46102
Logger.Print(var_str.str_value!);
47103
scope.UnregisterVariable(var_str.name);
48104
}));
49105
scope.RegisterFunction("print_scope", new NativeFunction((scope) => {
106+
Logger.Print("[AutoMaTA] Current Scope: ");
50107
Logger.Print(scope.ToString());
51108
}));
52109
// register extensions
@@ -60,7 +117,7 @@ public static void Main(string[] args)
60117
scope.ImportParser(parser);
61118
ICallable? main_function = scope.GetFunction("main");
62119
if (main_function == null)
63-
Logger.Print("No main function");
120+
Logger.Print("[AutoMaTA] No main function");
64121
else
65122
main_function.Call(scope);
66123
}

AutomataProcessor/Properties/PublishProfiles/FolderProfile.pubxml.user

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
44
-->
55
<Project>
66
<PropertyGroup>
7-
<History>True|2024-04-01T20:01:33.8067446Z;True|2024-04-01T22:47:25.6144360+03:00;True|2024-04-01T22:40:14.8267824+03:00;</History>
7+
<History>True|2024-04-02T14:28:27.3954276Z;True|2024-04-02T17:25:11.2272992+03:00;True|2024-04-02T17:24:20.8162814+03:00;True|2024-04-02T17:19:37.7487918+03:00;True|2024-04-02T17:17:42.8576628+03:00;True|2024-04-01T23:01:33.8067446+03:00;True|2024-04-01T22:47:25.6144360+03:00;True|2024-04-01T22:40:14.8267824+03:00;</History>
88
<LastFailureDetails />
99
</PropertyGroup>
1010
</Project>

0 commit comments

Comments
 (0)