0

我正在为我的 mpeg ts 解析器库编写简单的命令行应用程序,我无法根据用户选择的选项设置变量所需的选项

public enum TableType
{
    PAT,
    PMT,
    SDT,
    BAT,
    NIT,
    CAT,
    TOT,
    TDT,
}

public enum ParseType
{
    table,
    packet,
    service,
    lcn,
    gnr,
}

public class Options:TableOptions,PacketOptions,ServiceOptions
{
    [Option('g',"get", Required = true, HelpText = "Select parse type: table, packet, service, lcn, gnr")]
    public ParseType SelectedParseType { get; set; }
    public TableType SelectedTableType { get; set; }
    public uint? SelectedPid { get; set; }
    public string SelectedService { get; set; }
}

public interface TableOptions
{
    [Option('t',"table", Required = false, SetName = "table", HelpText = "Select table type. PAT, PMT, SDT, BAT, NIT, CAT, TOT, TDT")]
    public TableType SelectedTableType { get; set; }
}

public interface PacketOptions
{
    [Option('p',"pid",Required = false, SetName = "packet", HelpText ="Selected PID")]
    public uint? SelectedPid { get; set; }
}

public interface ServiceOptions
{
    [Option('s',"service",Required = false, SetName ="service", HelpText ="Selected service: service name, service id or ALL")]
    public string SelectedService { get; set; }
}

[Verb("stream", HelpText = "UDP multicast stream")]
public class StreamOptions : Options
{
    [Option('m', "multicastaddress", Required = true, HelpText = "Multicast destination address.")]
    public string MulticastAddress { get; set; }

    [Option('p', "port", Required = true, HelpText = "Multicast port")]
    public int UdpPort { get; set; }

    [Option('i', "mcastInterfaceAddress", Required = false, HelpText = "Multicast interface ip address")]
    public string McastInterfaceAddress { get; set; }
}

[Verb("file", HelpText = "Transport stream file")]
public class FileOptions : Options
{
    [Option('f', "filename", Required = true, HelpText = "Transport stream file")]
    public string FileName { get; set; }
}

我需要实现这个逻辑:

  • 用户可以选择文件或多播流作为源(只需选择其中之一)
  • 使用这两个源用户只能获得一种解析类型(表、服务、数据包等)//根据需要设置此选项属性。

这是我的麻烦:

  • 如果用户选择表选项,用户必须设置表类型
  • 如果用户选择数据包选项,用户必须设置数据包 pid
  • 如果用户选择服务选项,用户必须设置服务名称或服务ID,而不是两者。

我无法为所有这些选项设置 required 属性,因为在这种情况下,用户必须设置所有这些选项。

如何使用命令行解析器库实现此逻辑?

4

0 回答 0