Skip to content

Commit

Permalink
Add the ability to add global converters and get all subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
yakovypg committed Jan 27, 2025
1 parent 075c0d7 commit 825b66b
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions Core/NetArgumentParser/src/Subcommands/ParserQuantum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public virtual void ResetOptionsHandledState()
}
}

public void AddOptions(params ICommonOption[] options)
public virtual void AddOptions(params ICommonOption[] options)
{
ExtendedArgumentNullException.ThrowIfNull(options, nameof(options));
DefaultGroup.AddOptions(options);
Expand All @@ -80,7 +80,7 @@ public virtual bool RemoveOption(ICommonOption commonOption)
return _optionSet.RemoveOption(commonOption);
}

public void AddConverters(params IValueConverter[] converters)
public virtual void AddConverters(params IValueConverter[] converters)
{
ExtendedArgumentNullException.ThrowIfNull(converters, nameof(converters));
Array.ForEach(converters, _optionSet.AddConverter);
Expand All @@ -92,6 +92,21 @@ public virtual bool RemoveConverter(IValueConverter converter)
return _optionSet.RemoveConverter(converter);
}

public virtual void AddConverters(bool includeAllSubcommands, params IValueConverter[] converters)
{
ExtendedArgumentNullException.ThrowIfNull(converters, nameof(converters));

AddConverters(converters);

if (includeAllSubcommands)
{
foreach (Subcommand subcommand in Subcommands)
{
subcommand.AddConverters(includeAllSubcommands, converters);
}
}
}

public OptionGroup<ICommonOption> AddOptionGroup(string name, string? description = null)
{
ExtendedArgumentNullException.ThrowIfNull(name, nameof(name));
Expand Down Expand Up @@ -123,6 +138,19 @@ public IList<ICommonOption> GetAllOptions()
return options;
}

public IList<Subcommand> GetAllSubcommands()
{
var subcommands = new List<Subcommand>(Subcommands);

foreach (Subcommand subcommand in _subcommands)
{
IList<Subcommand> currSubcommands = subcommand.GetAllSubcommands();
subcommands.AddRange(currSubcommands);
}

return subcommands;
}

public Subcommand AddSubcommand(string name, string description)
{
ExtendedArgumentNullException.ThrowIfNull(name, nameof(name));
Expand Down

0 comments on commit 825b66b

Please sign in to comment.