-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgo-plugin.cs
More file actions
50 lines (44 loc) · 1.41 KB
/
go-plugin.cs
File metadata and controls
50 lines (44 loc) · 1.41 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
48
49
50
using ILeoConsole.Core;
using ILeoConsole;
using System.Text.Json;
namespace LeoConsole_External
{
public class PluginDataJson {
public string Description { get; set; }
}
public class GoPlugin : ICommand
{
public string Name { get; set; }
public string Description { get; set; }
public Action CommandFunction { get { return () => Command(); } }
public Action HelpFunction { get { return () => Console.WriteLine("not available"); } }
private string[] _Arguments;
public string[] Arguments { get { return _Arguments; } set { _Arguments = value; } }
public IData data = new ConsoleData();
public GoPlugin(string name, string savePath)
{
Name = name;
Description = JsonSerializer.Deserialize<PluginDataJson>(
Processes.CheckOutput(Path.Join(savePath, "share", "go-plugin", Name), $"init {Utils.EncodeData(data)}", savePath)
).Description;
}
public void Command()
{
string args = "";
for (int i = 1; i < _Arguments.Length; i++)
{
args = $"{args} {_Arguments[i]}";
}
int exitCode = Processes.Run(
Path.Join(data.SavePath, "share", "go-plugin", Name),
$"command {Utils.EncodeData(data)} {args}",
data.SavePath
);
if (exitCode != 0)
{
LConsole.MessageErr0($"cannot execute {Name}");
}
}
}
}
// vim: tabstop=2 softtabstop=2 shiftwidth=2 expandtab