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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Remora.Commands/Attributes/HiddenFromHelpAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// 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>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
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;
}
}
}
33 changes: 33 additions & 0 deletions Remora.Commands/CommandInformation/CommandBranch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// CommandBranch.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 OneOf;

namespace Remora.Commands.CommandInformation
{
/// <inheritdoc />
public sealed record CommandBranch
(
IGroupInfo GroupInfo,
OneOf<ICommandInfo, ICommandInfo[]> Commands
) : ICommandBranch;
}
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;
}
29 changes: 29 additions & 0 deletions Remora.Commands/CommandInformation/ConditionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// 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;

namespace Remora.Commands.CommandInformation
{
/// <inheritdoc />
public sealed record ConditionInfo(string Name, string? Description, IReadOnlyList<IConditionPropertyInfo> ConditionProperties) : IConditionInfo;
}
31 changes: 31 additions & 0 deletions Remora.Commands/CommandInformation/ConditionPropertyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// ConditionPropertyInfo.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;
using JetBrains.Annotations;

namespace Remora.Commands.CommandInformation
{
/// <inheritdoc />
[PublicAPI]
public sealed record ConditionPropertyInfo(string Name, bool CanRead, bool CanWrite, Type PropertyType, object? Value) : IConditionPropertyInfo;
}
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;
}
42 changes: 42 additions & 0 deletions Remora.Commands/CommandInformation/ICommandBranch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// ICommandBranch.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 OneOf;

namespace Remora.Commands.CommandInformation
{
/// <summary>
/// Represents a branch within the command system.
/// </summary>
public interface ICommandBranch
{
/// <summary>
/// Gets the command group which was found at the level searched.
/// </summary>
IGroupInfo GroupInfo { get; }

/// <summary>
/// Gets the command or all overloaded commands found at the level searched.
/// </summary>
OneOf<ICommandInfo, ICommandInfo[]> Commands { 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