adamabdelhamed / PowerArgs

The ultimate .NET Standard command line argument parser
MIT License
568 stars 56 forks source link

Question: How to require an argument only if another argument has specific value? #130

Closed BlackDragonBE closed 5 years ago

BlackDragonBE commented 6 years ago

For example:

I have this:

[ArgRequired(PromptIfMissing = false), ArgShortcut("u"), ArgDescription("Upload images to WordPress and replace links in files? (true/false)")]
public bool UploadImages { get; set; }

I want to have the following arguments to be required only when the above is true:

[ArgRequired(PromptIfMissing = true,If = "UploadImages"), ArgShortcut("user"), ArgDescription("Username")]
public string Username { get; set; }

[ArgRequired(PromptIfMissing = true,If = "UploadImages"), ArgShortcut("pw"), ArgDescription("Password")]
public string Password { get; set; }

Is there a way to do that? Something like ArgRequired(IfValueOf("UploadImages", "True")) would be ideal, but if there's another way, I'd love to hear it. Currently it prompts even if UploadImages is set to false.

Thanks in advance! Cheers

adamabdelhamed commented 6 years ago

You could implement a custom validator or a custom hook.