-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changing Parse method #157
Comments
I need to refresh my memory why we decided to implement it this way. Maybe because we use a lot of different contexts, but I still don't see any reason to pass it in. Without looking at the code, does the context specify behavior on how to parser should behave? |
Parser fill the newly created context - original command line, parameters, detect help switch |
I am happy to change this, but we need to be careful since we can't immediately break it. What if we introduce a 2nd overload, and if that works fine, we can make the other one obsolete. Interested in doing a PR? |
Yes, I'll try |
We are currently investigating some things in Orc.CommandLine. Will look into this as well. |
The downside is that we can no longer pass in options of a context. Maybe we could / should solve that with CommandLineParseOptions. |
Pushed a full refactoring. It's not actually a hotfix, but we are still in beta for our products so happy to take this breaking change as a hotfix and be done with it. |
@abrca please review the 4.0.1 hotfix branch. |
ok |
It works fine, quite obvious behavior. But as you start full refactoring, I have some suggestions, based on standards of unix command-line arguments processing. N0. N1. N2. N3. N4. Extend "-h" handling - "/?", "-?", "--help", etc. N5.
in context, where Color is
correctly recognize "-c Red" as Color.Red. But is this case seems more correct not to use enum elements names in command-line, but some text representation.
or use Catel's DisplayAttribute N6. N7. In this case (for console app), if we HasWarnings in ValidationContext - we can show warnings and short .GetUsage() N8. N9. |
Great review comments. Will try to respond on them point by point: N0: we used to have single char, but then we ran out of options fast for some of our commands. Therefore, we implemented it as a string. Obviously, you as a developer are free to only use single characters. N1: Due to reasoning for N0, I think this can become extremely complex. One of our use cases is to have extensions allow custom command line options. So we parse command line contexts per extension and allow an extension to respond. This will become extremely complex in such a scenario N2 / N3 / N4 / N6 / N7: Great points. Interested in doing (separate!) PRs on this? N5: This will make it extremely complex since the enum usage needs to be aware that it's being automated for a command line, and seems to be the wrong approach. In such case, I think it's best to create an "intermediate" option and use that instead. N8: Not sure what you mean, but that seems like string interpolation? (see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated) N9: This will probably not happen. We have core validation in Catel, and don't actively use FluentValidation ourselves (but moved it over for historical reasons). We don't want to take a dependency on it. |
Thanks for comments. N0 (shortName as char): N3 ("--version") and N8 |
Yes please, then we will deploy 4.0.1 as if it was a 4.0 release ;-) About N8: I believe we did add support for translating enums (DisplayAttribute in Catel). Maybe we can indeed leverage the ILanguageService of Catel for this. But how do we provide backwards compatibility to ensure that you can use fixed strings as well. Need to think about this for a while, but maybe you have a good solution in mind? |
Example:
offhand, in pseudo-code: (1)
to avoid conflicts in translation tables (if the same word but with another meaning already have translation), some hardcoded prefix can be used (or 2) use property name from context ("MyColor" in this example) as Key and:
no problem with unwanted spaces (if it is a problem). |
I think 1 is actually a good method. Then people can always implement it with keys if they prefer that instead. |
N3 (copyright info) - PR done N4 (add more Help options) - seems not needed - "?" already supported |
No need for the obsolete stuff for now. N4: we do support ?, but not the others (which I think are a great idea) |
N4: We can return to N0 with point As you extend shortName from char to string, the difference between shortName and longName becomes minimal, so we can change longName behavior. If we agree that What do you think? BTW, while reading GNU Coding Standards, an interesting idea crystallizes - as we have some pre-defined well-known licenses - GPL, Apache, BSD, MIT, CC, etc., and Also this feature can replace/extend Orchestra.Core\Resources\ThirdPartyNotices\ In conjunction with WebView2-preview license can be shown in windows from it's home page - no need to keep all texts, only links. It can be integrated in Orc.LicenseManager or, may be some new Orc.LicenseHelper To tell the truth, I don’t know if anyone will need it - but the idea is interesting |
N0: not sure about this just yet, for us that would be a "massive" breaking change while the rest so far isn't. Let me think about that one a bit longer. Maybe create options for it (we have the parse options now luckily :) ) For example, we can introduce We do need to write unit tests for this since we have regular expressions taking care of the parsing.
I think the lib functionality will explode if we move this from Orchestra to Orc.Controls. Eventually, it's up to the caller to hook this all up together (so we might need to make the Version method virtual on the IHelpWriterService). |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I think we should no longer consider this. We should consider using System.CommandLine instead of this one (maybe mark this package as obsolete). |
IF YOU DON'T ANSWER THIS TEMPLATE - THE BOT WILL AUTOMATICALLY CLOSE YOUR ISSUE!
Summary
More obvious behavior
API Changes
simple program, as visual example:
Intended Use Case
pay attention to three lines:
here we define new context, pass it as a value(!) to the parser, and suddenly we get it changed (using SetValue in UpdateContext in Parsers\CommandLineParser.cs)
This is very unobvious behavior, as it seems to me, violating the ideology of C#
my suggestion is:
validation becomes part of ContextBase and Parse method return new context, like:
The text was updated successfully, but these errors were encountered: