diff --git a/Core/NetArgumentParser/src/Options/IOptionGroup.cs b/Core/NetArgumentParser/src/Options/IOptionGroup.cs new file mode 100644 index 0000000..88f1c79 --- /dev/null +++ b/Core/NetArgumentParser/src/Options/IOptionGroup.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace NetArgumentParser.Options; + +public interface IOptionGroup + where T : IOption +{ + string Header { get; set; } + string Description { get; set; } + IReadOnlyList Options { get; } + + void AddOptions(params T[] options); + bool RemoveOption(T item); +} diff --git a/Core/NetArgumentParser/src/Options/MutuallyExclusiveOptionGroup.cs b/Core/NetArgumentParser/src/Options/MutuallyExclusiveOptionGroup.cs index c472446..904aec1 100644 --- a/Core/NetArgumentParser/src/Options/MutuallyExclusiveOptionGroup.cs +++ b/Core/NetArgumentParser/src/Options/MutuallyExclusiveOptionGroup.cs @@ -3,13 +3,21 @@ namespace NetArgumentParser.Options; -public sealed class MutuallyExclusiveOptionGroup +public sealed class MutuallyExclusiveOptionGroup : IOptionGroup where T : IOption { private readonly List _options; + private string _header; + private string _description; - internal MutuallyExclusiveOptionGroup(IEnumerable? options = null) + internal MutuallyExclusiveOptionGroup( + string header, + string description, + IEnumerable? options = null) { + _header = header; + _description = description; + _options = options is not null ? [.. options] : []; @@ -17,15 +25,27 @@ internal MutuallyExclusiveOptionGroup(IEnumerable? options = null) public IReadOnlyList Options => _options; + public string Header + { + get => _header; + set => _header = value ?? string.Empty; + } + + public string Description + { + get => _description; + set => _description = value ?? string.Empty; + } + public void AddOptions(params T[] options) { ExtendedArgumentNullException.ThrowIfNull(options, nameof(options)); Array.ForEach(options, _options.Add); } - public bool RemoveOption(T option) + public bool RemoveOption(T item) { - ExtendedArgumentNullException.ThrowIfNull(option, nameof(option)); - return _options.Remove(option); + ExtendedArgumentNullException.ThrowIfNull(item, nameof(item)); + return _options.Remove(item); } } diff --git a/Core/NetArgumentParser/src/Options/OptionGroup.cs b/Core/NetArgumentParser/src/Options/OptionGroup.cs index 23fd4ad..8f65256 100644 --- a/Core/NetArgumentParser/src/Options/OptionGroup.cs +++ b/Core/NetArgumentParser/src/Options/OptionGroup.cs @@ -4,7 +4,7 @@ namespace NetArgumentParser.Options; -public sealed class OptionGroup +public sealed class OptionGroup : IOptionGroup where T : IOption { private readonly List _options; @@ -50,11 +50,11 @@ public void AddOptions(params T[] options) Array.ForEach(options, _options.Add); } - public bool RemoveOption(T option) + public bool RemoveOption(T item) { - ExtendedArgumentNullException.ThrowIfNull(option, nameof(option)); + ExtendedArgumentNullException.ThrowIfNull(item, nameof(item)); - return OptionSet.RemoveOption(option) - && _options.Remove(option); + return OptionSet.RemoveOption(item) + && _options.Remove(item); } }