处理命令行main函数args参数

引用 System.CommandLine 库(需要显示预览版才能看到)

        var fileOption = new Option<FileInfo?>(
            name: "--file",
            description: "The file to read and display on the console.");

        var rootCommand = new RootCommand("Sample app for System.CommandLine");
        rootCommand.AddOption(fileOption);

        rootCommand.SetHandler((file) => 
            { 
                ReadFile(file!); 
            },
            fileOption);

        return await rootCommand.InvokeAsync(args);
posted @ 2023-10-26 10:23  IWing  阅读(6)  评论(0编辑  收藏  举报