-
Notifications
You must be signed in to change notification settings - Fork 395
SARIF invocation properties from InvocationContext #1795
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
Comments
I got the redaction almost working. I defined
Redact if Argument.ValueType is RedactableString or assignable to IEnumerable<RedactableString>. The remaining difficulty is how to place "--" at the correct location. It is listed in InvocationContext.ParseResult.Tokens but AFAICT nowhere in InvocationContext.ParseResult.RootCommandResult. Normally, I'd inject "--" before the first argument that starts with "-" and does not belong to an option, but I cannot do that here because System.CommandLine parses "--foo" as an argument if no "--foo" option is defined, and it allows options after that argument. Can I rely on SymbolResult.Tokens referring to the same Token instances that are in ParseResult.Tokens? If so, I can use the SymbolResult instances to collect the redaction information to a reference-equality dictionary and then enumerate ParseResult.Tokens and redact each token according to the dictionary. |
I now have it working, based on reference equality of Token instances. |
I wouldn't need to rely on reference equality if Token.Position were public. |
I have a tool that uses System.CommandLine and can create a Static Analysis Results Interchange Format (SARIF) Version 2.1.0 log file. SARIF defines the
invocation.commandLine
,invocation.arguments
, andinvocation.responseFiles
properties in which the tool can save information about how it was invoked. I'd like to implement that in the tool. I am not requesting any changes in System.CommandLine for this purpose, but I am curious if anyone else has implemented something similar.It would be easy to use
string[] args
from the Main method for the SARIFinvocation.arguments
property, and Environment.CommandLine for the SARIFinvocation.commandLine
property. However, I hope I can instead get the information from System.CommandLine somehow, for these reasons:invocation.responseFiles
property, especially if the syntax can change later (Does not allow arguments that start with the '@' character #1625).For the SARIF
invocation.arguments
property, there are ParseResult.Directives and ParseResult.Tokens, which would let the tool check the sensitivity markers, but I cannot fully reconstruct the originalstring[] args
from them:--option=value
,--option:value
, and--option
value
. Non-public reflection could perhaps do it by checking whether both tokens have the same Token.Position. As above, the difference shouldn't matter in practice.So, it seems I can make the tool log a
invocation.arguments
property that is good enough although not quite perfect, but I cannot make it loginvocation.commandLine
(too difficult to redact) norinvocation.responseFiles
(too difficult to find which files were used, and the tokens from the files will be ininvocation.arguments
).The text was updated successfully, but these errors were encountered: