Skip to content
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

Multitool --force option: advertised default is false, actual default is true. #1340

Closed
jeffersonking opened this issue Mar 8, 2019 · 2 comments

Comments

@jeffersonking
Copy link
Collaborator

Repeat invocations of smt transform input.sarif --output transformed.sarif will overwrite the output file.

Expected: Since --force flag was not set, transformed.sarif should not be overwritten.

@michaelcfanning
Copy link
Member

Not good.

@ghost ghost self-assigned this Aug 5, 2019
@ghost ghost added the bug label Aug 5, 2019
@ghost
Copy link

ghost commented Aug 6, 2019

I ran all the multitool commands, and the only ones that respect --force are convert and file-work-items.

@ghost ghost closed this as completed in 5a3ac7d Aug 9, 2019
@ghost ghost added the resolved-fixed label Aug 9, 2019
ghost pushed a commit that referenced this issue Aug 22, 2019
This addresses one of a set of about 10 bugs I recently filed in the course of fixing #1340 ("Multitool --force option: advertised default is false, actual default is true"). I discovered that there were widespread inconsistencies in the behaviors and underlying implementations of the various commands related to their treatment of command line options. This was one of them.

As usual, I took the opportunity to address IDE code warnings, improve documentation, and generally clean up the code I came in contact with while investigating the bug.

The core of the fix is the introduction of the method(s) `ValidateOutputOptions` in DriverExtensionMethods.cs. The code in each Multitool command is rearranged or enhanced to invoke these methods.

Notes:

1. I implemented the options validation methods in Sarif.Driver rather than in Sarif.Multitool because that's where the options classes themselves are defined. It's not obvious that that's where they belong.

2. The validation methods use a helper method `GetOptionDescription` that takes an option property such as `SingleFileOptionsBase.Force` and creates a description for the option like `"-p, --pretty-print"`, which is the format that the CommandLine package uses. This method was originally defined in Sarif.Multitool, but since it is now needed in Sarif.Driver, I moved it there. The corresponding unit test file moved to Test.UnitTests.Sarif.Driver.

4. As I've mentioned before, our unit test namespaces are a hodgepodge. In the same assembly, you can find tests in the namespaces `Microsoft.CodeAnalysis.Sarif.Multitool`, `Microsoft.CodeAnalysis.Test.UnitTests.Sarif.Multitool`, and `Test.UnitTests.Sarif.Multitool`. This makes it hard to find  your tests in the Test Explorer. Per @michaelcfanning I'm standardizing on `Microsoft.CodeAnalysis.Sarif.Multitool`. I'll modify the test project files (or build.props, if I can think of a way to automate it) accordingly in a later PR.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants