Skip to content

Commit 33cbc39

Browse files
improve script arguments
1 parent 69d73c5 commit 33cbc39

File tree

5 files changed

+95
-177
lines changed

5 files changed

+95
-177
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using JetBrains.Annotations;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.Helpers.ResultSystem;
4+
using SER.ScriptSystem;
5+
using SER.TokenSystem.Tokens;
6+
7+
namespace SER.ArgumentSystem.Arguments;
8+
9+
public class CreatedScriptArgument(string name) : Argument(name)
10+
{
11+
public override string InputDescription => "Name of a script to create";
12+
13+
[UsedImplicitly]
14+
public DynamicTryGet<Script> GetConvertSolution(BaseToken token)
15+
{
16+
return new(() => Script.CreateByScriptName(token.GetBestTextRepresentation(Script), null));
17+
}
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Linq;
2+
using JetBrains.Annotations;
3+
using SER.ArgumentSystem.BaseArguments;
4+
using SER.Helpers.ResultSystem;
5+
using SER.ScriptSystem;
6+
using SER.TokenSystem.Tokens;
7+
8+
namespace SER.ArgumentSystem.Arguments;
9+
10+
public class RunningScriptArgument(string name) : Argument(name)
11+
{
12+
public override string InputDescription => "Name of a currently running script";
13+
14+
[UsedImplicitly]
15+
public DynamicTryGet<Script> GetConvertSolution(BaseToken token)
16+
{
17+
return new(() =>
18+
{
19+
var name = token.GetBestTextRepresentation(Script);
20+
if (Script.RunningScripts.FirstOrDefault(scr => scr.Name == name) is not {} runningScript)
21+
{
22+
return $"There is no running script named '{name}'";
23+
}
24+
25+
return runningScript;
26+
});
27+
}
28+
}

ArgumentSystem/Arguments/ScriptArgument.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using JetBrains.Annotations;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.Helpers.ResultSystem;
4+
using SER.ScriptSystem.Structures;
5+
using SER.TokenSystem.Tokens;
6+
7+
namespace SER.ArgumentSystem.Arguments;
8+
9+
public class ScriptNameArgument(string name) : Argument(name)
10+
{
11+
public override string InputDescription => "Name of a script";
12+
13+
[UsedImplicitly]
14+
public DynamicTryGet<ScriptName> GetConvertSolution(BaseToken token)
15+
{
16+
return new(() =>
17+
{
18+
var name = token.GetBestTextRepresentation(Script);
19+
return ScriptName.TryInit(name);
20+
});
21+
}
22+
}

0 commit comments

Comments
 (0)