Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add CommandHelpService #14

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
50 changes: 50 additions & 0 deletions Remora.Commands/Attributes/HiddenFromHelpAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// HiddenFromHelpAttribute.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System;

namespace Remora.Commands.Attributes
{
/// <summary>
/// Marks a command or group as being hidden from the help service.
/// </summary>
/// <remarks>
/// This attribute represents a request to be hidden. The implementing
/// service may or may not respect this request.
/// </remarks>
public sealed class HiddenFromHelpAttribute : Attribute
{
/// <summary>
/// Gets a comment provided by the developer, if any.
/// </summary>
public string? Comment { get; }

/// <summary>
/// Initializes a new instance of the <see cref="HiddenFromHelpAttribute"/> class.
/// </summary>
/// <param name="comment">A comment describing why this is hidden or any relevant notes. May be displayed by the help service.</param>
public HiddenFromHelpAttribute(string? comment = null)
{
Comment = comment;
}
}
}
38 changes: 38 additions & 0 deletions Remora.Commands/CommandInformation/CommandArgumentInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// CommandArgumentInfo.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System;

namespace Remora.Commands.CommandInformation
{
/// <inheritdoc />
public sealed record CommandArgumentInfo
Foxtrek64 marked this conversation as resolved.
Show resolved Hide resolved
(
string Name,
string Description,
int Position,
Type ArgumentType,
bool IsOptional,
bool HasDefaultValue,
object? DefaultValue
) : ICommandArgumentInfo;
}
39 changes: 39 additions & 0 deletions Remora.Commands/CommandInformation/CommandInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// CommandInfo.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;
using System.Reflection;

namespace Remora.Commands.CommandInformation
{
/// <inheritdoc />
public sealed record CommandInfo
(
string Name,
string? Description,
IReadOnlyList<string> Aliases,
bool Hidden,
string? HiddenFromHelpComment,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the naming of this property - could we come up with a better name?

IReadOnlyList<IConditionInfo> Conditions,
IReadOnlyList<ParameterInfo> Arguments
) : ICommandInfo;
}
30 changes: 30 additions & 0 deletions Remora.Commands/CommandInformation/ConditionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// ConditionInfo.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;
using System.Reflection;

namespace Remora.Commands.CommandInformation
{
/// <inheritdoc />
public sealed record ConditionInfo(string Name, string? Description, IReadOnlyList<IConditionPropertyInfo> ConditionProperties) : IConditionInfo;
}
38 changes: 38 additions & 0 deletions Remora.Commands/CommandInformation/GroupInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// GroupInfo.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;

namespace Remora.Commands.CommandInformation
{
/// <inheritdoc />
public sealed record GroupInfo
(
string Name,
string? Description,
IReadOnlyList<string> Aliases,
bool Hidden,
string? HiddenFromHelpComment,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

IReadOnlyList<ICommandInfo> Commands,
IReadOnlyList<IGroupInfo> ChildGroups
) : IGroupInfo;
}
68 changes: 68 additions & 0 deletions Remora.Commands/CommandInformation/ICommandArgumentInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// ICommandArgumentInfo.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System;

namespace Remora.Commands.CommandInformation
{
/// <summary>
/// Contains information about a specific command argument.
/// </summary>
public interface ICommandArgumentInfo
{
/// <summary>
/// Gets the name of the argument.
/// </summary>
string Name { get; }

/// <summary>
/// Gets the argument's description, if any.
/// </summary>
string? Description { get; }

/// <summary>
/// Gets the position of the argument.
/// </summary>
int Position { get; }

/// <summary>
/// Gets the type of the argument.
/// </summary>
Type ArgumentType { get; }

/// <summary>
/// Gets a value indicating whether the argument is optional.
/// </summary>
bool IsOptional { get; }

/// <summary>
/// Gets a value indicating whether a default value is present.
/// </summary>
bool HasDefaultValue { get; }

/// <summary>
/// Gets the provided default value, if present.
/// </summary>
/// <exception cref="InvalidOperationException">Throws when <see cref="HasDefaultValue"/> is false.</exception>
object? DefaultValue { get; }
}
}
68 changes: 68 additions & 0 deletions Remora.Commands/CommandInformation/ICommandInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// ICommandInfo.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;
using System.Reflection;

namespace Remora.Commands.CommandInformation
{
/// <summary>
/// Contains information about a specific command.
/// </summary>
public interface ICommandInfo
{
/// <summary>
/// Gets the name of the command.
/// </summary>
string Name { get; }

/// <summary>
/// Gets the command's description, if any.
/// </summary>
string? Description { get; }

/// <summary>
/// Gets a read-only list of the command's aliases.
/// </summary>
IReadOnlyList<string> Aliases { get; }

/// <summary>
/// Gets a value indicating whether the command was requested to be hidden from help commands.
/// </summary>
bool Hidden { get; }

/// <summary>
/// Gets a comment describing why the command is hidden.
/// </summary>
string? HiddenFromHelpComment { get; }

/// <summary>
/// Gets a read-only list of any command conditions.
/// </summary>
IReadOnlyList<IConditionInfo> Conditions { get; }

/// <summary>
/// Gets a read-only list of any command arguments.
/// </summary>
IReadOnlyList<ParameterInfo> Arguments { get; }
}
}
47 changes: 47 additions & 0 deletions Remora.Commands/CommandInformation/IConditionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// IConditionInfo.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;

namespace Remora.Commands.CommandInformation
{
/// <summary>
/// Contains information about a specific command condition.
/// </summary>
public interface IConditionInfo
{
/// <summary>
/// Gets the display name of the condition.
/// </summary>
string Name { get; }

/// <summary>
/// Gets the description of the condition, if any.
/// </summary>
string? Description { get; }

/// <summary>
/// Gets a list of properties belonging to the condition this type represents.
/// </summary>
IReadOnlyList<IConditionPropertyInfo> ConditionProperties { get; }
}
}
Loading