Nuget“ types”参数期望的命令行解析器包是什么?

时间:2018-07-11 09:09:07

标签: c# visual-studio

我找不到任何有用的文档或示例,这些示例或示例似乎使用的版本与我相同,因此需要此参数。目前,我已经定义了一个包含参数的类:

public class CmdArgs {
    // Required
    [Option("ifp", HelpText = "Input filepath", Required = true)]
    public string path_csv_in {get; set; }

    [Option("ofp", HelpText = "Output filepath", Required = true)]
    public string path_csv_out {get; set; }

    [Option("dfp", HelpText = "Deck filepath", Required = true)]
    public string path_deck_in {get; set; }

    [Option("ffp", HelpText = "Fortran .dll filepath", Required = true)]
    public string dll_path {get; set; }

    [Option("gfs", HelpText = "Gas fuel spec", Required = true)]
    public string path_gas_fuel_spec {get; set; }

    [Option("lfs", HelpText = "Liquid fuel spec", Required = true)]
    public string path_liq_fuel_spec {get; set; }

    [Option("dut", HelpText = "Driven unit type: PG or MD", Required = true)]
    public string type_du {get; set; }

    [Option("mgr", HelpText = "Main gearbox ratio", Required = true)]
    public string ratio_gb_main {get; set; }


    // Not required
    [Option("cts", HelpText = "CT capacity scale factor: Default is ..", Required = false, Default = ..)]
    public string ct_scale_f {get; set; }

    [Option("ipl", HelpText = "Inlet pressure loss, nominal: Default is ..", Required = false, Default = ..)]
    public string plin_nom {get; set; }

    [Option("epl", HelpText = "Exhaust pressure loss, nominal: Default is ..", Required = false, Default = ..)]
    public string plex_nom {get; set; }

    [Option("bpl", HelpText = "Exhaust pressure loss, bypass: Default is ..", Required = false, Default = ..)]
    public string plex_bp {get; set; }

    [Option("aef", HelpText = "Alternator efficiency", Required = false, Default = ..)]
    public string effic_alt {get; set; }
}

对象初始化程序:

CmdArgs ops = new CmdArgs();

和解析器:

Parser.Default.ParseArguments(args);

某些示例似乎仅使用'args'参数,但是在'debug:命令行参数'中使用这些参数运行:(用通用路径等替换了路径和参数)

-ifp "ifpPath" 
-ofp "ofpPath" 
-dfp "dfpPath" 
-ffp "ffpPath" 
-gfs "gfsPath" 
-lfs "lfsPath" 
-dut "duType" 
-mgr "gearboxRatio" 
-cts "ctScale" 
-ipl "inletPressureLoss" 
-epl "exhaustPressureLoss" 
-bpl "bypassPressureLoss" 
-aef "alternatorEfficiency"

throws'指定的参数超出有效值范围。参数名称:类型,以及在向“ ParseArguments”中输入参数时的工具提示指出需要args和“ params Type []类型”,但这是什么?我找不到有用的东西,也无法找到答案。

谢谢

1 个答案:

答案 0 :(得分:0)

更改行

Parser.Default.ParseArguments(args);

进入

Parser.Default.ParseArguments(args, ops);

您必须在解析这些参数的地方指定

编辑尽管进一步研究,以上内容是针对先前版本(1.9)的。

对于当前版本(2.2),根据the docs,您应该执行以下操作:

CommandLine.Parser.Default.ParseArguments<CmdArgs>(args)
  .WithParsed<CmdArgs>(opts => RunWithOptions(opts));

其中RunWithOptions是您定义的运行“真实”代码的方法(并接受填充的CmdArgs对象作为参数)。

类似的东西:

private static void RunWithOptions(CmdArgs options)
{
   // use the "options" to perform the real work
}