VersionOption doesn't ever use the short getter
See original GitHub issueSteps to Reproduce
- Clone this repo (at commit 92481fac0cf8ccc8345af7f785a4a50d29675534 at time of reporting)
- Build the solution using
build.cmd
- Run C# Interactive (
csi.exe
) - Add reference to
McMaster.Extensions.CommandLineUtils.dll
via#r
- Execute the following:
using McMaster.Extensions.CommandLineUtils; var app = new CommandLineApplication(throwOnUnexpectedArg: false); app.VersionOption("-v|--version", () => "version (short)", () => "version (long)"); app.Execute(new[] { "-v" }); app.Execute(new[] { "--version" });
Expected Output
Expected the line app.Execute(new[] { "-v" });
to print version (short)
and the line app.Execute(new[] { "--version" });
to print version (long)
.
Actual Output
Microsoft (R) Visual C# Interactive Compiler version 2.7.0.62715
Copyright (C) Microsoft Corporation. All rights reserved.
Type "#help" for more information.
> #r "A:\CommandLineUtils\.build\bin\McMaster.Extensions.CommandLineUtils\Debug\net45\McMaster.Extensions.CommandLineUtils.dll"
> using McMaster.Extensions.CommandLineUtils;
> var app = new CommandLineApplication(throwOnUnexpectedArg: false);
> app.VersionOption("-v|--version", () => "version (short)", () => "version (long)");
> app.Execute(new[] { "-v" });
version (long)
> app.Execute(new[] { "--version" });
version (long)
Both of the following lines:
app.Execute(new[] { "-v" });
app.Execute(new[] { "--version" });
print version (long)
, which is incorrect. There seems to be no way to distinguish between the two when VersionOption
specifically allows one to have a short and a long getter.
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (11 by maintainers)
Top Results From Across the Web
Manipulating C# Shorthand Getter-Setter
My question is... Is there any way to keep the shorthand styled property yet manipulate it to have my ternary operator? Nearly all...
Read more >Avoid getters and setters whenever possible
The argument is that getters/setters and properties VIOLATE ENCAPSULATION by exposing internals as properties rather than mutating through ...
Read more >Is there a better way of using getters and setters on private ...
I have the member of the class set as private and to set and get this member, I have made get and set...
Read more >I never use getter setters, am I bad? (C#)
I am really kind of thinking, when working on small projects, or even 1-man indie game projects, whats the point? Except for typing...
Read more >Getters and Setters: Manage Attributes in Python
This issue occurs because the getter and setter methods are hidden inside the property. They're not inherited independently but as a whole.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@atruskie Thanks for the very detailed and awesome response.
I’m well aware of this but you have to admit, irrespective of what it does under the hood (for the curious few who bother to read the help on help and pop and look under the hood) is irrelevant because the end effect is that to the uninformed user,
-h
appears like an alias for--help
. Now we can argue whether that’s intended or it’s really two separation options (which I think what it is):I’m not arguing for long and short forms should do different things. As far as version display goes, there are different ways to go about it like you suggested. I’d even say the following is confusing:
What I’d rather see is combining options. Suppose:
So if you use
--version
, you get the short version display. If you specify--version
with-v
or--verbose
then you get a more detailed display. You can also go the other way if you have a-q
or--quiet
option, where--version
will give you the longer display by default but combined with-q
or--quiet
will give the short machine-readable format. I can even imagine--version --machine
.Anyway, I think we’ve gone a bit off track here. The issue title reads, “VersionOption doesn’t ever use the short getter” and that’s all I meant to highlight as a bug. I didn’t want to argue here the merits or perils of using the long and short form of an option to change the display of what is logically the same information. Even if I was to argue that, it would be confined to version and version display only. I would never suggest that an application should use long and short forms as a general approach to switch between machine-readable and human-readable output. It’s much better to have an explicit option to flag that and version display doesn’t have to be an exception to that rule. I guess
VersionOption
mislead me there given its signature and I can admit that I was being mischievous 😇 and taking advantage of (what appeared to be) its support for long and short version display.Ok, how about this as a hotfix to unblock you @atifaziz? --> #96
@atruskie you’re comments connect well with some refactoring I’ve been considering. I don’t like that
--version
and--help
are special-cased in the parser. As we’ve discovered, it makes it hard to extend and customize their behavior, or to add your own version/help options. Users end up putting code at the top of the OnExecute block to check for “special” options. Maybe that’s okay, but I was thinking of generalizing this behavior; I just haven’t landed on an implementation I like yet.