using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Reflection; namespace Unity.Pipeline.Commands { /// /// Information about a discovered CLI command. /// Contains metadata needed for command execution and CLI help generation. /// public class CommandInfo { /// /// Unique name of the command for CLI execution. /// public string Name { get; } /// /// Human-readable description of the command. /// public string Description { get; } /// /// Whether this command requires Unity main thread execution. /// public bool MainThreadRequired { get; } /// /// Whether this command is part of the runtime (Player) command surface only. /// Editor servers hide runtime-only commands from their command listing. /// public bool RuntimeOnly { get; } /// /// Hierarchical tags used to group and browse commands (path-style, '/'-separated). /// Empty for untagged commands; never null. /// public IReadOnlyList Tags { get; } /// /// Name of the assembly this command originates from, used to group and filter /// commands by contributing package/source. /// public string Package { get; } /// /// Method that implements this command. /// public MethodInfo Method { get; } // TODO Maybe look at generating a dynamic Delegate to increase performance of the command call. /// /// Parameters that this command accepts. /// public IReadOnlyList Parameters { get; } /// /// Instance to invoke on, or null when is static. /// Commands declared with a [CliCommand] attribute are always static and leave this null; /// a dynamically registered command bound to an instance method carries its receiver here. /// public object Target { get; } /// /// Create command information from discovery. /// /// Unique name of the command for CLI execution. /// Human-readable description of the command. /// Whether this command requires Unity main thread execution. /// Method that implements this command. /// Parameters that this command accepts. /// Whether this command is part of the runtime (Player) command surface only. /// Hierarchical tags used to group and browse commands. /// Name of the assembly this command originates from. /// /// Instance to invoke on, or null when it is static. Only a /// dynamically registered command bound to an instance method supplies one. /// public CommandInfo(string name, string description, bool mainThreadRequired, MethodInfo method, IReadOnlyList parameters, bool runtimeOnly = false, IReadOnlyList tags = null, string package = null, object target = null) { Name = name ?? throw new ArgumentNullException(nameof(name)); Description = description ?? throw new ArgumentNullException(nameof(description)); Method = method ?? throw new ArgumentNullException(nameof(method)); Parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); MainThreadRequired = mainThreadRequired; RuntimeOnly = runtimeOnly; Tags = tags ?? Array.Empty(); Package = package; Target = target; } /// A short diagnostic summary of the command. /// The summary string. public override string ToString() { return $"{Name} MainThreadRequired:{MainThreadRequired} Parameters:{Parameters.Count}"; } } }