-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
housekeeping: code analysis to 4.8 and restrict to sln file on comman…
…d line (#239)
- Loading branch information
Showing
4 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Dhgms.GripeWithRoslyn.Cmd/CommandLine/ArgumentExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2019 DHGMS Solutions and Contributors. All rights reserved. | ||
// This file is licensed to you under the MIT license. | ||
// See the LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.CommandLine; | ||
using System.CommandLine.Parsing; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Dhgms.GripeWithRoslyn.Cmd.CommandLine | ||
{ | ||
internal static class ArgumentExtensions | ||
{ | ||
internal static Argument<FileInfo> SpecificFileExtensionOnly(this Argument<FileInfo> argument, string extension) | ||
{ | ||
argument.AddValidator(result => FileHasSupportedExtension(result, extension)); | ||
return argument; | ||
} | ||
|
||
internal static Argument<FileInfo> SpecificFileExtensionOnly(this Argument<FileInfo> argument, string[] extensions) | ||
{ | ||
argument.AddValidator(result => FileHasSupportedExtension(result, extensions)); | ||
return argument; | ||
} | ||
|
||
internal static void FileHasSupportedExtension(ArgumentResult result, string extension) | ||
{ | ||
for (var i = 0; i < result.Tokens.Count; i++) | ||
{ | ||
var token = result.Tokens[i]; | ||
|
||
var tokenExtension = Path.GetExtension(token.Value); | ||
|
||
if (string.IsNullOrWhiteSpace(tokenExtension) | ||
|| !tokenExtension.Equals(extension, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
result.ErrorMessage = $"Filename does not have a supported extension of \"{extension}\"."; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
internal static void FileHasSupportedExtension(ArgumentResult result, string[] extensions) | ||
{ | ||
for (var i = 0; i < result.Tokens.Count; i++) | ||
{ | ||
var token = result.Tokens[i]; | ||
|
||
var tokenExtension = Path.GetExtension(token.Value); | ||
|
||
if (string.IsNullOrWhiteSpace(tokenExtension) | ||
|| !extensions.Any(extension => tokenExtension.Equals(extension, StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
result.ErrorMessage = $"Filename does not have a supported extension of \"{string.Join(",", extensions)}\"."; | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters