mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 17:47:24 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using System.Text.RegularExpressions;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.ContentPack;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Shared.Console.Commands
|
|
{
|
|
[UsedImplicitly]
|
|
internal sealed partial class ExecCommand : LocalizedCommands
|
|
{
|
|
private static readonly Regex CommentRegex = new Regex(@"^\s*#");
|
|
|
|
[Dependency] private IResourceManager _resources = default!;
|
|
|
|
public override string Command => "exec";
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length < 1)
|
|
{
|
|
shell.WriteError("No file specified!");
|
|
return;
|
|
}
|
|
|
|
var path = new ResPath(args[0]).ToRootedPath();
|
|
if (!_resources.UserData.Exists(path))
|
|
{
|
|
shell.WriteError("File does not exist.");
|
|
return;
|
|
}
|
|
|
|
using var text = _resources.UserData.OpenText(path);
|
|
while (true)
|
|
{
|
|
var line = text.ReadLine();
|
|
if (line == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(line) || CommentRegex.IsMatch(line))
|
|
{
|
|
// Comment or whitespace.
|
|
continue;
|
|
}
|
|
|
|
shell.ConsoleHost.AppendCommand(line);
|
|
}
|
|
}
|
|
|
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
var hint = Loc.GetString("cmd-exec-arg-filename");
|
|
var options = CompletionHelper.UserFilePath(args[0], _resources.UserData);
|
|
|
|
return CompletionResult.FromHintOptions(options, hint);
|
|
}
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|
|
}
|