From ad64d0330c872813b350a73b3d9f2ba72bbcd5ef Mon Sep 17 00:00:00 2001 From: Flipp Syder <76629141+vulppine@users.noreply.github.com> Date: Mon, 10 Oct 2022 22:35:34 -0700 Subject: [PATCH] Fix nuke command exception, add autocomplete (#11828) * fix nuke command exception, add autocomplete * caches entity manager --- .../Nuke/Commands/SendNukeCodesCommand.cs | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/Content.Server/Nuke/Commands/SendNukeCodesCommand.cs b/Content.Server/Nuke/Commands/SendNukeCodesCommand.cs index e555f45f60..83a0081389 100644 --- a/Content.Server/Nuke/Commands/SendNukeCodesCommand.cs +++ b/Content.Server/Nuke/Commands/SendNukeCodesCommand.cs @@ -1,4 +1,6 @@ -using Content.Server.Administration; +using System.Linq; +using Content.Server.Administration; +using Content.Server.Station.Systems; using Content.Shared.Administration; using JetBrains.Annotations; using Robust.Shared.Console; @@ -13,19 +15,48 @@ namespace Content.Server.Nuke.Commands public string Description => "Send nuke codes to a station's communication consoles"; public string Help => "nukecodes [station EntityUid]"; + [Dependency] private readonly IEntityManager _entityManager = default!; + + public SendNukeCodesCommand() + { + IoCManager.InjectDependencies(this); + } + public void Execute(IConsoleShell shell, string argStr, string[] args) { if (args.Length != 1) { - shell.WriteError("shell-need-exactly-one-argument"); + shell.WriteError(Loc.GetString("shell-need-exactly-one-argument")); + return; } if (!EntityUid.TryParse(args[0], out var uid)) { shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number")); + return; } - IoCManager.Resolve().System().SendNukeCodes(uid); + _entityManager.System().SendNukeCodes(uid); + } + + public CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + if (args.Length != 1) + { + return CompletionResult.Empty; + } + + var stations = _entityManager + .System() + .Stations + .Select(station => + { + var meta = _entityManager.GetComponent(station); + + return new CompletionOption(station.ToString(), meta.EntityName); + }); + + return CompletionResult.FromHintOptions(stations, null); } } }