Проблема : я обнаружил, что если я помесчу команду «преобразование» и ее опцию в командную строку, то только его ручной работы вызывается, но не для команды root. Поэтому у меня нет возможности определить значения параметров root команды -i и -o.
Код: Выделить всё
public class Program
{
public static async Task Main(string[] args)
{
// Conversion command
var thresholdOpt = new Option("--threshold");
var conversionCommand = new Command("conversion") { thresholdOpt };
conversionCommand.SetHandler(
(int threshold) => { Console.WriteLine($"threshold={threshold}"); },
thresholdOpt);
// Root command
var infileOpt = new Option("--i");
var outfileOpt = new Option("--o");
var rootCommand = new RootCommand("test") { infileOpt, outfileOpt, conversionCommand };
rootCommand.SetHandler(
(string i, string o) => { Console.WriteLine($"i={i}, o={o}"); },
infileOpt, outfileOpt);
return await rootCommand.InvokeAsync(args);
}
}
Код: Выделить всё
> myapp --i infile.dat --o outfile.dat conversion --threshold 42
threshold=42
ожидаемые результаты :
Код: Выделить всё
> myapp --i infile.dat --o outfile.dat
i=infile.dat, o=outfile.dat
> myapp conversion --threshold 42
threshold=42
зависимости [/b]: я использую System.commandline 2.0.0-beta3.22114.1, system.commandline.namingconventionbinder v2.0.0-beta3.22114.1, .net 6.0 и Visual Studio 17.1. Благодарен за помощь в понимании того, что я делаю не так. Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/722 ... th-options