-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from adambajguz/feature/issue-186_dynamic-com…
…mands Feature/issue 186 dynamic commands
- Loading branch information
Showing
239 changed files
with
4,646 additions
and
1,506 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
10 changes: 5 additions & 5 deletions
10
src/Typin/Benchmarks/Typin.Benchmarks.FrameworksComparison/Commands/TypinCommand.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
10 changes: 5 additions & 5 deletions
10
src/Typin/Benchmarks/Typin.Benchmarks.MultiCommand/TypinCommands/TypinBaseCommand.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
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
62 changes: 62 additions & 0 deletions
62
src/Typin/Examples/InteractiveModeExample/Commands/AddDynamicCommand.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace InteractiveModeExample.Commands | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Typin; | ||
using Typin.Attributes; | ||
using Typin.Console; | ||
using Typin.DynamicCommands; | ||
using Typin.Metadata; | ||
using Typin.Schemas; | ||
|
||
[Command("add dynamic", Description = "Adds a dynamic command.")] | ||
public class AddDynamicCommand : ICommand | ||
{ | ||
private readonly IConsole _console; | ||
private readonly IDynamicCommandBuilderFactory _dynamicCommandBuilderFactory; | ||
private readonly RootSchema _rootSchema; | ||
|
||
[Option("name")] | ||
public string Name { get; init; } = string.Empty; | ||
|
||
public AddDynamicCommand(IConsole console, IDynamicCommandBuilderFactory dynamicCommandBuilderFactory, IRootSchemaAccessor rootSchemaAccessor) | ||
{ | ||
_console = console; | ||
_dynamicCommandBuilderFactory = dynamicCommandBuilderFactory; | ||
_rootSchema = rootSchemaAccessor.RootSchema; | ||
} | ||
|
||
public ValueTask ExecuteAsync(CancellationToken cancellationToken) | ||
{ | ||
CommandSchema commandSchema = _dynamicCommandBuilderFactory.Create<SampleDynamicCommand>(Name) | ||
.WithDescription("Test description.") | ||
.WithManual("Some manual\nadd dynamic --name abc\nabc 5 j --number 4 -a aaaaaa\nabc --help.") | ||
.AddOption<int>("Number", (ob) => ob | ||
.AsRequired() | ||
.WithDescription("Some number.") | ||
.SetMetadata(new ArgumentMetadata("test")) | ||
) | ||
.AddOption(typeof(double)) | ||
.AddOption<int>((ob) => ob | ||
.SetMetadata(new ArgumentMetadata("test")) | ||
) | ||
.AddOption<string>("Str") | ||
.AddOption(typeof(double), "Price") | ||
.AddParameter<string>("Parameter", 0) | ||
.AddParameter<string>(1) | ||
.Build(); | ||
|
||
if (_rootSchema.TryAddDynamicCommand(commandSchema)) | ||
{ | ||
_console.Output.WithForegroundColor(ConsoleColor.Green, (err) => err.WriteLine($"Successfully added dynamic command '{Name}'.")); | ||
} | ||
else | ||
{ | ||
_console.Error.WithForegroundColor(ConsoleColor.Red, (err) => err.WriteLine($"Failed to add dynamic command '{Name}'.")); | ||
} | ||
|
||
return default; | ||
} | ||
} | ||
} |
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.