-
-
Notifications
You must be signed in to change notification settings - Fork 257
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
Add support for --no-option #334
Comments
I've seen the |
After though: I've also seen |
We have some options wich csn be enabled in configuration. Now there might be an occasional call where you want to temporarily override configuration. Also if you are writing scripts and don't control the local configuration, you may want to explicitly state, that is is off. (Verbose, color-output, …) You can do this with an (optional) value, but I prefer While I may prefer |
I think this idea needs to be fleshed out a little more. I thought I knew what you were asking, but then your response didn't fit with my original assumptions. Maybe I'm just dense. Can you share some code snippets of what you think the completed feature would look like for the end user? |
@natemcmaster this is a common pattern used in compilers and other such tools (configure, etc) and is used to invert the default meaning of a switch. However I do believe @TheConstructor's definition is a little too broad and confusing. I suggest this feature be limited to boolean, long named switches. The absence of a valued option indicates Controlling compiler warnings:
The first switch enables all warnings, then the following two disable specific warnings, and the opposite is also true:
By default all warnings are disabled, and we're enabling two of them. I propose the following syntax: (pseudo code, and naming conventions are just suggestions)
Usage is The toggle prefix is declared by convention as the first stanza in the option declaration string. Presence of the prefixed switch indicates An alternative prefix specification is The alternative usage of |
@JakeSays your suggestion on toggle enum is an interesting idea. I think I would implement it slightly differently though. What do you think of usage that looks like this? Option<ToggleState> myMappedOption = app.AddMappedOption<ToggleState>(o =>
{
o.Map("--yes", ToggleState.Yes);
o.Map("--no", ToggleState.No);
o.Map("--maybe-so", ToggleState.Maybe);
});
// or with attributes
public class Program
{
[MappedOption("--yes", ToggleState.Yes)]
[MappedOption("--no", ToggleState.No)]
[MappedOption("--maybe-so", ToggleState.Maybe)]
public ToggleState State { get; set; }
} |
@natemcmaster Is that mapping a prefix to a state? I am a little unclear on how it would be used. How would I get from Also |
Sorry, allow me to clarify. I meant for Option<FruitOption> myMappedOption = app.AddMappedOption<FruitOption>(o =>
{
o.Map("--banana", FruitOption.Banana);
o.Map("--apple", FruitOption.Apple);
o.Map("--pear", FruitOption.Pear);
});
// or with attributes
public class Program
{
[MappedOption("--banana", FruitOption.Banana)]
[MappedOption("--apple", FruitOption.Apple)]
[MappedOption("--pear", FruitOption.Pear)]
public FruitOption Fruit { get; set; }
} I think this would be generic enough to support the uses cases above enum TouchScreen
{
Enabled,
Disabled
}
app.AddMappedOption<TouchScreen>(o =>
{
o.Map("--disable-touch-screen", TouchScreen.Disabled);
o.Map("--enable-touch-screen", TouchScreen.Enabled);
});
enum MyFeature
{
Yes,
No
}
app.AddMappedOption<MyFeature>(o =>
{
o.Map("--feature", MyFeature.Yes);
o.Map("--no-feature", MyFeature.No);
}); |
@natemcmaster ahh ok. I see now. Yes, I think that would work nicely. The only scenario that isn't covered is I believe this could also solve #329. Would it make sense to have AddMappedShortOption(o =>
{
o.Map("-T", TouchScreen.Enabled);
}); I personally wouldn't use it, but someone might. |
I'd rather just have one API which supports both short and long options. Option<FruitOption> myMappedOption = app.AddMappedOption<FruitOption>(o =>
{
o.Map("-b|--banana", FruitOption.Banana);
o.Map("-a", FruitOption.Apple);
o.Map("-p|--pear", FruitOption.Pear);
}); |
Ah. Yes of course - makes total sense. |
While your suggestion would nicely cover the parsing (without another field), I have some questions:
or
my preferred way of
would probably require either a custom help-provider, or we could 'misue' the outer mapped-option to carry two fields for documentation purposes
public class Program
{
[MappedOption("--banana", FruitOption.Banana)] // default NoValue
[MappedOption("--apple", FruitOption.Apple, CommandOptionType.SingleValue)]
[MappedOption("--pear", FruitOption.Pear, CommandOptionType.SingleOrNoValue)]
public (FruitOption fruit, string color) Fruit { get; }
}
|
@TheConstructor Some thoughts:
public (FruitOption fruit, string color) Fruit { get; } What is the purpose of the above tuple? What would the string represent? If you are considering having both the value switches and For this:
It may make sense to base multiplicity off of the property type. If the property is a container then it would implicitly support multiple values. |
My two cents:
I was planning to start with this for simplicity:
We can provide overrides for those who want to customize this more.
No, I don't think so. This scenario sounds more like PowerShell's parameter sets, which is a feature of PowerShell that I personally hate and find confusing whenever I've encountered it.
Too complicated. |
Building towards natemcmaster#334 null should only reach this parser for CommandOptionTypes NoValue or SingleOrNoValue - in both cases true is more likely to be desired.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project. |
#451 is still work in progress |
This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project. |
Closing due to inactivity. |
I got two ideas on how to do this:
bool?
-type options making all three states reachableno
-value. This would enable./configure
like--no-dep
/--dep=xyz
stuffI don't have an idea how to apply this to short-options (
--no-s
as negation of-s
feels slightly off).Currently you can define a second option to get a similar behavior. Main benefit would be less boilerplate and a shorter help-text.
I am willing to implement this myself if the idea sounds sound to you.
The text was updated successfully, but these errors were encountered: