using System.Linq; using Content.Shared.Administration; using Content.Shared.Tag; using Robust.Shared.Prototypes; using Robust.Shared.Toolshed; using Robust.Shared.Toolshed.Syntax; using Robust.Shared.Toolshed.TypeParsers; namespace Content.Server.Administration.Toolshed; [ToolshedCommand, AdminCommand(AdminFlags.Debug)] public sealed class TagCommand : ToolshedCommand { private TagSystem? _tag; [CommandImplementation("list")] public IEnumerable> List([PipedArgument] IEnumerable ent) { return ent.SelectMany(x => { if (TryComp(x, out var tags)) // Note: Cast is required for C# to figure out the type signature. return (IEnumerable>)tags.Tags; return Array.Empty>(); }); } [CommandImplementation("with")] public IEnumerable With( [CommandInvocationContext] IInvocationContext ctx, [PipedArgument] IEnumerable entities, [CommandArgument] ValueRef> tag) { _tag ??= GetSys(); return entities.Where(e => _tag.HasTag(e, tag.Evaluate(ctx)!)); } [CommandImplementation("add")] public EntityUid Add([PipedArgument] EntityUid input, ProtoId tag) { _tag ??= GetSys(); _tag.AddTag(input, tag); return input; } [CommandImplementation("add")] public IEnumerable Add([PipedArgument] IEnumerable input, ProtoId tag) => input.Select(x => Add(x, tag)); [CommandImplementation("rm")] public EntityUid Rm([PipedArgument] EntityUid input, ProtoId tag) { _tag ??= GetSys(); _tag.RemoveTag(input, tag); return input; } [CommandImplementation("rm")] public IEnumerable Rm([PipedArgument] IEnumerable input, ProtoId tag) => input.Select(x => Rm(x, tag)); [CommandImplementation("addmany")] public EntityUid AddMany([PipedArgument] EntityUid input, IEnumerable> tags) { _tag ??= GetSys(); _tag.AddTags(input, tags); return input; } [CommandImplementation("addmany")] public IEnumerable AddMany([PipedArgument] IEnumerable input, IEnumerable> tags) => input.Select(x => AddMany(x, tags.ToArray())); [CommandImplementation("rmmany")] public EntityUid RmMany([PipedArgument] EntityUid input, IEnumerable> tags) { _tag ??= GetSys(); _tag.RemoveTags(input, tags); return input; } [CommandImplementation("rmmany")] public IEnumerable RmMany([PipedArgument] IEnumerable input, IEnumerable> tags) => input.Select(x => RmMany(x, tags.ToArray())); }