Skip to content

Container

Axwabo edited this page Mar 2, 2025 · 3 revisions

Container Commands

See this article on command basics.

Container commands (aka. parent commands) encapsulate subcommands. The first argument of the container command will be used to invoke a subcommand.

Important

A container command may not have multiple subcommands with the same name. Aliases may overlap with a command's name; however, command name takes priority over aliases.

Example:

using Axwabo.CommandSystem.Attributes;
using Axwabo.CommandSystem.Attributes.Containers;
using Axwabo.CommandSystem.Commands;

[CommandProperties(CommandHandlerType.RemoteAdmin, "container")]
[UsesSubcommands(typeof(Subcommand1), typeof(Subcommand2))]
public sealed class MyContainerCommand : ContainerCommand;

Important

All class-based subcommands must inherit CommandBase and must be flagged as a subcommand using one of the following ways:

  • Add the Axwabo.CommandSystem.Attributes.Containers.UsesSubcommandsAttribute to the container command and specify the types of subcommands (see above example)
  • Add the Axwabo.CommandSystem.Attributes.Containers.SubcommandOfContainerAttribute to a subcommand class and specify the container command type as such:
using System;
using Axwabo.CommandSystem.Attributes;
using Axwabo.CommandSystem.Attributes.Containers;
using Axwabo.CommandSystem.Commands;

[CommandName("subcommand3")]
[SubcommandOfContainer(typeof(MyContainerCommand))]
public sealed class Subcommand3 : CommandBase
{

    protected override CommandResult Execute(ArraySegment<string> arguments, CommandSender sender)
    {
        return "Subcommand 3";
    }

}

Method-based subcommands

Methods in the container command's class can also be created to register subcommands. The requirements are the following:

  • Method is a public instance method
  • Attribute Axwabo.CommandSystem.Attributes.Containers.MethodBasedSubcommandAttribute is present
  • Returns a Axwabo.CommandSystem.CommandResult
  • Parameters are either
    • ArraySegment<string> CommandSender
    • List<ReferenceHub> ArraySegment<string> CommandSender (see UnifiedTargetingCommand)

Note

Inheriting from a container that specifies method-based subcommands will register all inherited methods as subcommands of the derived container.

If the command name is not specified with attributes, the method name will be used.

Example:

using System;
using Axwabo.CommandSystem.Attributes;
using Axwabo.CommandSystem.Attributes.Containers;
using Axwabo.CommandSystem.Commands;

[CommandProperties(CommandHandlerType.RemoteAdmin, "container")]
public sealed class MyContainerCommand : ContainerCommand
{

    [MethodBasedSubcommand]
    [CommandDescription("Example subcommand")]
    public CommandResult Subcommand(ArraySegment<string> arguments, CommandSender sender)
    {
        return "This is a subcommand";
    }

}
Clone this wiki locally