commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Detecting switches

Open ajtruckle opened this issue 1 year ago • 1 comments

I am getting confused here:

public class Options
{
    [Option('c', "create", Required = false, HelpText = "Creates an empty CSV. Eg: -c \".\\File.csv\"")]
    public string EmptyCsvFilePath { get; set; }
    [Option('x', "clm", Required = false, HelpText = "Import history from CLM Explorer. Eg: -x \".\\File.csv\"")]
    public string ClmExplorerHistoryPath { get; set; }
    [Option('h', "hist", Required = false, HelpText = "Import generic history. Eg: -h \".\\File.csv\"")]
    public string GenericHistoryPath { get; set; }
}

All these switched are optional. But, if the switch is used then the values must be provided.

How do I handle this? At the moment the paths are null if either the switch is not provided or no path is provided. But it is only an issue if the switch was provided and no path.

if a switch is provided, it should have a value.

Using latest stable release.

Please help me. Thanks.

ajtruckle avatar Mar 31 '24 19:03 ajtruckle

Update ... these is my current set of switches:

public class Options
{
    [Option("log", Required = true, HelpText = "Path to log file. Eg: --log \".\\logfile.txt\"")]
    public string LogFile { get; set; }
    [Option('c', "create", Required = false, HelpText = "Creates an empty CSV. Eg: -c --csv \".\\file.csv\"")]
    public bool CreateCsvFile { get; set; }
    [Option("csv", Required = false, HelpText = "Specifies CSV filename. Eg: --csv \".\\file.csv\"")]
    public string CsvFilePath { get; set; }
    [Option("xml", Required = false, HelpText = "Specifies XML filename. Eg: --xml \".\\file.xml\"")]
    public string XmlFilePath { get; set; }
    [Option('t', "test", Required = false, HelpText = "For testing. Eg: -t --csv \".\\file.csv\"  --xml \".\\file.xml\"")]
    public bool DoTest { get; set; }
    [Option("lang", Required = false, HelpText = "Specifies the language code. Eg: --lang ENG")]
    public string LanguageCode { get; set; }
    [Option("json", Required = false, HelpText = "Specifies the JSON text. Eg: --json \"json\"")]
    public string Json { get; set; }
    [Option("mode", Required = false, HelpText = "Specifies the import mode. Eg: --mode clm")]
    public string ImportMode { get; set; }
}

I have chosen to include some bool switches. So if the user passes -c or --create for example, then I test to see if the CsvFilePath is valid. Is this the right way to go about it?

For --mode I manually test the value between clm and generic. Can that be factored into the option settings so any other value is flagged?

ajtruckle avatar Apr 01 '24 17:04 ajtruckle