-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added parent command accessor support
- Added parent command accessor support. Sub-commands can get a reference to the parent command by adding a property of the parent command type. - ParseResultExtensions.Bind improvement: Binding will be done only once per definition class, so calling this method consecutively for the same definition class will return the cached result.
- Loading branch information
Showing
220 changed files
with
2,655 additions
and
1,480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 78 additions & 64 deletions
142
src/DotMake.CommandLine.SourceGeneration/CliCommandInfo.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.CommandLine; | ||
|
||
namespace DotMake.CommandLine | ||
{ | ||
/// <summary> | ||
/// Provides extension methods for <see cref="ParseResult"/>. | ||
/// </summary> | ||
public static class ParseResultExtensions | ||
{ | ||
private static readonly ConcurrentDictionary<ParseResult, ConcurrentDictionary<Type, object>> BindResults = new(); | ||
|
||
/// <inheritdoc cref = "Bind{TDefinition}" /> | ||
/// <typeparam name="TDefinition"><inheritdoc cref="Cli.GetConfiguration{TDefinition}" path="/typeparam[@name='TDefinition']/node()" /></typeparam> | ||
public static TDefinition Bind<TDefinition>(this ParseResult parseResult) | ||
{ | ||
var commandBuilder = CliCommandBuilder.Get<TDefinition>(); | ||
|
||
return (TDefinition)commandBuilder.Bind(parseResult); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the command definition class and binds/populates the properties from the parse result. | ||
/// Note that binding will be done only once per definition class, so calling this method consecutively for | ||
/// the same definition class will return the cached result. | ||
/// <para> | ||
/// If the command line input is not for the indicated definition class (e.g. it's for a sub-command but not for | ||
/// the indicated root command or vice versa), then the returned instance would be empty (i.e. properties would have default values). | ||
/// </para> | ||
/// </summary> | ||
/// <param name="parseResult">A parse result describing the outcome of the parse operation.</param> | ||
/// <param name="definitionType"><inheritdoc cref="Cli.GetConfiguration(Type, CliSettings)" path="/param[@name='definitionType']/node()" /></param> | ||
/// <returns>An instance of the definition class whose properties were bound/populated from the parse result.</returns> | ||
public static object Bind(this ParseResult parseResult, Type definitionType) | ||
{ | ||
var commandBuilder = CliCommandBuilder.Get(definitionType); | ||
|
||
return commandBuilder.Bind(parseResult); | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...otMake.CommandLine.SourceGeneration.CliCommandGenerator/(ModuleInitializerAttribute).g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...n/DotMake.CommandLine.SourceGeneration.CliCommandGenerator/(RequiredMemberAttribute).g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.