/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/standard/commandline/snippets/tab-completion/csharp/Program.cs
44 строки
1 KB
Tom Dykstra
System.CommandLine beta 4 (#29580)
02 июн 2022, 20:36
Не верифицирован
02 июн 2022, 20:36
375b2c5
Код
Авторство
О чём код?
// <all> using System.CommandLine; using System.CommandLine.Completions; using System.CommandLine.Parsing; await new DateCommand().InvokeAsync(args); class DateCommand : Command { private Argument<string> subjectArgument = new ("subject", "The subject of the appointment."); private Option<DateTime> dateOption = new ("--date", "The day of week to schedule. Should be within one week."); public DateCommand() : base("schedule", "Makes an appointment for sometime in the next week.") { this.AddArgument(subjectArgument); this.AddOption(dateOption); // <dateoption> dateOption.AddCompletions((ctx) => { var today = System.DateTime.Today; var dates = new List<CompletionItem>(); foreach (var i in Enumerable.Range(1, 7)) { var date = today.AddDays(i); // <completionitem> dates.Add(new CompletionItem( label: date.ToShortDateString(), sortText: $"{i:2}")); // </completionitem> } return dates; }); // </dateoption> this.SetHandler((subject, date) => { Console.WriteLine($"Scheduled \"{subject}\" for {date}"); }, subjectArgument, dateOption); } } // </all>