Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ ConsoleApp.ServiceProvider = scope.ServiceProvider;
* `app.AddSubCommands<T>` -> `app.Add<T>(string commandPath)`
* `app.AddAllCommandType` -> `NotSupported`(use `Add<T>` manually)
* `[Option(int index)]` -> `[Argument]`
* `[Option(string shortName, string description)]` -> `Xml Document Comment`
* `[Option(string shortName, string description)]` -> `Xml Document Comment`(Define short names as parameter aliases in the <param> description)
* `ConsoleAppFilter.Order` -> `NotSupported`(global -> class -> method declarative order)
* `ConsoleAppOptions.GlobalFilters` -> `app.UseFilter<T>`
* `ConsoleAppBase` -> inject `ConsoleAppContext`, `CancellationToken` to method
Expand Down
43 changes: 43 additions & 0 deletions tests/ConsoleAppFramework.GeneratorTests/RunTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,47 @@ public void Output(string msg = @"\\")
ConsoleApp.Run(args, (string msg = @"\\") => Console.Write(msg));
""", "", @"\\");
}

[Fact]
public void ShortNameAlias()
{
var code = """
var app = ConsoleApp.Create();
app.Add<FileCommand>();
app.Run(args);

public class FileCommand
{
/// <summary>Outputs the provided file name.</summary>
/// <param name="inputFile">-i, InputFile</param>
[Command("")]
public void Run(string inputFile) => Console.Write(inputFile);
}
""";

verifier.Execute(code, "--input-file sample.txt", "sample.txt");
verifier.Execute(code, "-i sample.txt", "sample.txt");
}

[Fact]
public void ShortNameAndLongNameAlias()
{
var code = """
var app = ConsoleApp.Create();
app.Add<FileCommand>();
app.Run(args);

public class FileCommand
{
/// <summary>Outputs the provided file name.</summary>
/// <param name="inputFile">-i|--input, InputFile</param>
[Command("")]
public void Run(string inputFile) => Console.Write(inputFile);
}
""";

verifier.Execute(code, "--input-file sample.txt", "sample.txt");
verifier.Execute(code, "--input sample.txt", "sample.txt");
verifier.Execute(code, "-i sample.txt", "sample.txt");
}
}