forked from dotnet/format
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormatCommand.cs
68 lines (62 loc) · 3.57 KB
/
FormatCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.
using System;
using System.CommandLine;
using System.CommandLine.Parsing;
using System.Linq;
namespace Microsoft.CodeAnalysis.Tools
{
internal static class FormatCommand
{
internal static string[] VerbosityLevels => new[] { "q", "quiet", "m", "minimal", "n", "normal", "d", "detailed", "diag", "diagnostic" };
internal static string[] SeverityLevels => new[] { FixSeverity.Info, FixSeverity.Warn, FixSeverity.Error };
internal static RootCommand CreateCommandLineOptions()
{
var rootCommand = new RootCommand
{
new Argument<string?>("workspace")
{
Arity = ArgumentArity.ZeroOrOne,
Description = Resources.A_path_to_a_solution_file_a_project_file_or_a_folder_containing_a_solution_or_project_file_If_a_path_is_not_specified_then_the_current_directory_is_used
}.LegalFilePathsOnly(),
new Option(new[] { "--folder", "-f" }, Resources.Whether_to_treat_the_workspace_argument_as_a_simple_folder_of_files),
new Option(new[] { "--fix-style", "-fs" }, Resources.Run_code_style_analyzer_and_apply_fixes)
{
Argument = new Argument<string?>("severity") { Arity = ArgumentArity.ZeroOrOne }.FromAmong(SeverityLevels)
},
new Option(new[] { "--fix-analyzers", "-fa" }, Resources.Run_code_style_analyzer_and_apply_fixes)
{
Argument = new Argument<string?>("severity") { Arity = ArgumentArity.ZeroOrOne }.FromAmong(SeverityLevels)
},
new Option(new[] { "--include" }, Resources.A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty)
{
Argument = new Argument<string[]>(() => Array.Empty<string>())
},
new Option(new[] { "--exclude" }, Resources.A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting)
{
Argument = new Argument<string[]>(() => Array.Empty<string>())
},
new Option(new[] { "--check" }, Resources.Formats_files_without_saving_changes_to_disk_Terminates_with_a_non_zero_exit_code_if_any_files_were_formatted),
new Option(new[] { "--report" }, Resources.Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory)
{
Argument = new Argument<string?>(() => null).LegalFilePathsOnly()
},
new Option(new[] { "--verbosity", "-v" }, Resources.Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic)
{
Argument = new Argument<string?>() { Arity = ArgumentArity.ExactlyOne }.FromAmong(VerbosityLevels)
},
new Option(new[] { "--include-generated" }, Resources.Include_generated_code_files_in_formatting_operations)
{
IsHidden = true
},
};
rootCommand.Description = "dotnet-format";
return rootCommand;
}
internal static bool WasOptionUsed(this ParseResult result, params string[] aliases)
{
return result.Tokens
.Where(token => token.Type == TokenType.Option)
.Any(token => aliases.Contains(token.Value));
}
}
}