Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting switches #924

Open
ajtruckle opened this issue Mar 31, 2024 · 1 comment
Open

Detecting switches #924

ajtruckle opened this issue Mar 31, 2024 · 1 comment

Comments

@ajtruckle
Copy link

ajtruckle commented Mar 31, 2024

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
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant