-
Notifications
You must be signed in to change notification settings - Fork 93
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
Fix #1629: Page command shouldn't throw on options error. #1654
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis.Sarif.Driver; | ||
|
@@ -40,22 +41,39 @@ public int Run(PageOptions options) | |
|
||
public int RunWithoutCatch(PageOptions options) | ||
{ | ||
// TODO: Report these to the console instead of throwing. | ||
if (options.RunIndex < 0) { throw new ArgumentOutOfRangeException("runIndex"); } | ||
if (options.Index < 0) { throw new ArgumentOutOfRangeException("index"); } | ||
if (options.Count < 0) { throw new ArgumentOutOfRangeException("count"); } | ||
if (!_fileSystem.FileExists(options.InputFilePath)) { throw new FileNotFoundException($"Input file \"{options.InputFilePath}\" not found."); } | ||
|
||
bool valid = DriverUtilities.ReportWhetherOutputFileCanBeCreated(options.OutputFilePath, options.Force, _fileSystem); | ||
if (!valid) { return 1; } | ||
if (!ValidateOptions(options, _fileSystem)) { return 1; } | ||
|
||
// Load the JsonMap, if previously built and up-to-date, or rebuild it | ||
JsonMapNode root = LoadOrRebuildMap(options); | ||
|
||
// Write the desired page from the Sarif file | ||
ExtractPage(options, root); | ||
|
||
return 1; | ||
return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This was just a bug :-) #ByDesign |
||
} | ||
|
||
internal bool ValidateOptions(PageOptions options, IFileSystem fileSystem) | ||
{ | ||
bool valid = true; | ||
|
||
valid &= ValidateNonNegativeCommandLineOption<PageOptions>(options.RunIndex, nameof(options.RunIndex)); | ||
valid &= ValidateNonNegativeCommandLineOption<PageOptions>(options.Index, nameof(options.Index)); | ||
valid &= ValidateNonNegativeCommandLineOption<PageOptions>(options.Count, nameof(options.Count)); | ||
|
||
|
||
if (!fileSystem.FileExists(options.InputFilePath)) | ||
{ | ||
Console.Error.WriteLine( | ||
string.Format( | ||
CultureInfo.CurrentCulture, | ||
MultitoolResources.InputFileNotFound, | ||
options.InputFilePath)); | ||
valid = false; | ||
} | ||
|
||
valid &= DriverUtilities.ReportWhetherOutputFileCanBeCreated(options.OutputFilePath, options.Force, fileSystem); | ||
|
||
return valid; | ||
} | ||
|
||
internal SarifLog PageViaOm(PageOptions options) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ internal class PageOptions | |
"force", | ||
Default = true, | ||
HelpText = "Force overwrite of output file if it exists.")] | ||
public bool Force { get; set; } = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a bug #1630, "Multitool page command --force defaults to true and can't be changed". This change does not fix that bug! Rather, this change makes it easier to write my new unit tests in PageCommandTests. Without this change, I had to explicitly set It makes sense to remove this initialization; I don't think there's a single other property in any of the options classes that's initialized like this. It also makes sense to fix #1630 by removing the Note that with |
||
public bool Force { get; set; } | ||
|
||
[Option( | ||
'o', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have another PR out that moves this method into
DriverUtilities
, so whoever gets in second will have a small merge conflict to resolve. #Pending