122 lines
3.1 KiB
C#
122 lines
3.1 KiB
C#
using StellaOps.Plugin.Abstractions;
|
|
|
|
namespace StellaOps.Plugin.Sdk;
|
|
|
|
|
|
/// <summary>
|
|
/// Fluent builder for creating PluginInfo.
|
|
/// </summary>
|
|
public sealed class PluginInfoBuilder
|
|
{
|
|
private string _id = "";
|
|
private string _name = "";
|
|
private string _version = "1.0.0";
|
|
private string _vendor = "";
|
|
private string? _description;
|
|
private string? _licenseId;
|
|
private string? _projectUrl;
|
|
private string? _iconUrl;
|
|
|
|
/// <summary>
|
|
/// Sets the plugin ID.
|
|
/// </summary>
|
|
/// <param name="id">Plugin ID in reverse domain notation (e.g., com.example.plugin).</param>
|
|
public PluginInfoBuilder WithId(string id)
|
|
{
|
|
_id = id;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the plugin name.
|
|
/// </summary>
|
|
/// <param name="name">Human-readable plugin name.</param>
|
|
public PluginInfoBuilder WithName(string name)
|
|
{
|
|
_name = name;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the plugin version.
|
|
/// </summary>
|
|
/// <param name="version">SemVer version string.</param>
|
|
public PluginInfoBuilder WithVersion(string version)
|
|
{
|
|
_version = version;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the plugin vendor.
|
|
/// </summary>
|
|
/// <param name="vendor">Vendor/company name.</param>
|
|
public PluginInfoBuilder WithVendor(string vendor)
|
|
{
|
|
_vendor = vendor;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the plugin description.
|
|
/// </summary>
|
|
/// <param name="description">Description of what the plugin does.</param>
|
|
public PluginInfoBuilder WithDescription(string description)
|
|
{
|
|
_description = description;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the plugin license.
|
|
/// </summary>
|
|
/// <param name="licenseId">SPDX license identifier.</param>
|
|
public PluginInfoBuilder WithLicense(string licenseId)
|
|
{
|
|
_licenseId = licenseId;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the plugin project URL.
|
|
/// </summary>
|
|
/// <param name="projectUrl">Project URL.</param>
|
|
public PluginInfoBuilder WithProjectUrl(string projectUrl)
|
|
{
|
|
_projectUrl = projectUrl;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the plugin icon URL.
|
|
/// </summary>
|
|
/// <param name="iconUrl">Icon URL.</param>
|
|
public PluginInfoBuilder WithIconUrl(string iconUrl)
|
|
{
|
|
_iconUrl = iconUrl;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Builds the PluginInfo.
|
|
/// </summary>
|
|
/// <exception cref="InvalidOperationException">If required fields are not set.</exception>
|
|
public PluginInfo Build()
|
|
{
|
|
if (string.IsNullOrEmpty(_id))
|
|
throw new InvalidOperationException("Plugin ID is required");
|
|
if (string.IsNullOrEmpty(_name))
|
|
throw new InvalidOperationException("Plugin name is required");
|
|
|
|
return new PluginInfo(
|
|
Id: _id,
|
|
Name: _name,
|
|
Version: _version,
|
|
Vendor: _vendor,
|
|
Description: _description,
|
|
LicenseId: _licenseId,
|
|
ProjectUrl: _projectUrl,
|
|
IconUrl: _iconUrl);
|
|
}
|
|
}
|