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

Use space-separated paths instead of comma-separated #551

Merged
merged 5 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,19 @@ dotnet tool install -g dotnet-format --version 4.0.111308 --add-source https://d

By default `dotnet-format` will look in the current directory for a project or solution file and use that as the workspace to format. If more than one project or solution file is present in the current directory you will need to specify the workspace to format using the `-w` or `-f` options. You can control how verbose the output will be by using the `-v` option.

```
```sh
Usage:
dotnet-format [options]

Options:
--folder, -f The folder to operate on. Cannot be used with the `--workspace` option.
--workspace, -w The solution or project file to operate on. If a file is not specified, the command will search
the current directory for one.
--include A comma separated list of relative file or folder paths to include in formatting. All files are
formatted if empty.
--exclude A comma separated list of relative file or folder paths to exclude from formatting.
--check Formats files without saving changes to disk. Terminates with a non-zero exit code if any files
were formatted.
--report Writes a json file to the given directory. Defaults to 'format-report.json' if no filename given.
--verbosity, -v Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and
diag[nostic]
--version Display version information
-f, --folder <FOLDER> The folder to operate on. Cannot be used with the `--workspace` option.
-w, --workspace <WORKSPACE> The solution or project file to operate on. If a file is not specified, the command will search the current directory for one.
--files, --include <INCLUDE> A list of relative file or folder paths to include in formatting. All files are formatted if empty.
--exclude <EXCLUDE> A list of relative file or folder paths to exclude from formatting.
--check, --dry-run <CHECK> Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.
--report <REPORT> Accepts a file path, which if provided, will produce a json report in the given directory.
-v, --verbosity <VERBOSITY> Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]
--version Display version information
```

Add `format` after `dotnet` and before the command arguments that you want to run:
Expand All @@ -69,7 +65,7 @@ Add `format` after `dotnet` and before the command arguments that you want to ru
| dotnet **format** -f &lt;folder&gt; | Formats a particular folder and subfolders. |
| dotnet **format** -w &lt;workspace&gt; | Formats a specific project or solution. |
| dotnet **format** -v diag | Formats with very verbose logging. |
| dotnet **format** --include Programs.cs,Utility\Logging.cs | Formats the files Program.cs and Utility\Logging.cs |
| dotnet **format** --include Programs.cs Utility\Logging.cs | Formats the files Program.cs and Utility\Logging.cs |
| dotnet **format** --check | Formats but does not save. Returns a non-zero exit code if any files would have been changed. |
| dotnet **format** --report &lt;report-path&gt; | Formats and saves a json report file to the given directory. |

Expand Down
2 changes: 1 addition & 1 deletion src/CodeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static async Task<WorkspaceFormatResult> FormatWorkspaceAsync(
foreach (var changedDocumentId in projectChanges.GetChangedDocuments())
{
var changedDocument = solution.GetDocument(changedDocumentId);
logger.LogInformation(Resources.Formatted_code_file_0, Path.GetFileName(changedDocument.FilePath));
logger.LogInformation(Resources.Formatted_code_file_0, changedDocument.FilePath);
filesFormatted++;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ private static async Task<int> Main(string[] args)
{
Argument = new Argument<string>(() => null)
},
new Option(new[] { "--include", "--files" }, Resources.A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty)
new Option(new[] { "--include", "--files" }, Resources.A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty)
{
Argument = new Argument<string>(() => null)
am11 marked this conversation as resolved.
Show resolved Hide resolved
},
new Option(new[] { "--exclude" }, Resources.A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting)
new Option(new[] { "--exclude" }, Resources.A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting)
{
Argument = new Argument<string>(() => null)
},
Expand All @@ -62,7 +62,7 @@ private static async Task<int> Main(string[] args)
return await rootCommand.InvokeAsync(args);
}

public static async Task<int> Run(string folder, string workspace, string verbosity, bool check, string include, string exclude, string report, IConsole console = null)
public static async Task<int> Run(string folder, string workspace, string verbosity, bool check, string[] include, string[] exclude, string report, IConsole console = null)
{
// Setup logging.
var serviceCollection = new ServiceCollection();
Expand Down Expand Up @@ -211,24 +211,24 @@ private static void ConfigureServices(ServiceCollection serviceCollection, ICons
}

/// <summary>
/// Converts a comma-separated list of relative file paths to a hashmap of full file paths.
/// Converts array of relative file paths to a hashmap of full file paths.
/// </summary>
internal static ImmutableHashSet<string> GetRootedPaths(string paths, string folder)
internal static ImmutableHashSet<string> GetRootedPaths(string[] paths, string folder)
{
if (string.IsNullOrEmpty(paths))
if (paths == null)
{
return ImmutableHashSet.Create<string>();
return ImmutableHashSet<string>.Empty;
}

if (string.IsNullOrEmpty(folder))
{
return paths.Split(',')
return paths
.Select(path => Path.GetFullPath(path, Environment.CurrentDirectory))
.ToImmutableHashSet(StringComparer.OrdinalIgnoreCase);
}
else
{
return paths.Split(',')
return paths
.Select(path => Path.GetFullPath(path, Environment.CurrentDirectory))
.Where(path => path.StartsWith(folder))
.ToImmutableHashSet(StringComparer.OrdinalIgnoreCase);
Expand Down
10 changes: 5 additions & 5 deletions src/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@
<data name="Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted" xml:space="preserve">
<value>Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</value>
</data>
<data name="A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty" xml:space="preserve">
<value>A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</value>
<data name="A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty" xml:space="preserve">
<value>A list of relative file or folder paths to include in formatting. All files are formatted if empty.</value>
</data>
<data name="Formatted_code_file_0" xml:space="preserve">
<value>Formatted code file '{0}'.</value>
Expand Down Expand Up @@ -216,7 +216,7 @@
<data name="Writing_formatting_report_to_0" xml:space="preserve">
<value>Writing formatting report to: '{0}'.</value>
</data>
<data name="A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting" xml:space="preserve">
<value>A comma separated list of relative file or folder paths to exclude from formatting.</value>
<data name="A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting" xml:space="preserve">
<value>A list of relative file or folder paths to exclude from formatting.</value>
</data>
</root>
</root>
12 changes: 6 additions & 6 deletions src/xlf/Resources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../Resources.resx">
<body>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A comma separated list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A comma separated list of relative file or folder paths to exclude from formatting.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A list of relative file or folder paths to exclude from formatting.</target>
<note />
</trans-unit>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<note />
</trans-unit>
<trans-unit id="Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory">
Expand Down
12 changes: 6 additions & 6 deletions src/xlf/Resources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../Resources.resx">
<body>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A comma separated list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A comma separated list of relative file or folder paths to exclude from formatting.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A list of relative file or folder paths to exclude from formatting.</target>
<note />
</trans-unit>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<note />
</trans-unit>
<trans-unit id="Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory">
Expand Down
12 changes: 6 additions & 6 deletions src/xlf/Resources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../Resources.resx">
<body>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A comma separated list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A comma separated list of relative file or folder paths to exclude from formatting.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A list of relative file or folder paths to exclude from formatting.</target>
<note />
</trans-unit>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<note />
</trans-unit>
<trans-unit id="Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory">
Expand Down
12 changes: 6 additions & 6 deletions src/xlf/Resources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../Resources.resx">
<body>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A comma separated list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A comma separated list of relative file or folder paths to exclude from formatting.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A list of relative file or folder paths to exclude from formatting.</target>
<note />
</trans-unit>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<note />
</trans-unit>
<trans-unit id="Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory">
Expand Down
12 changes: 6 additions & 6 deletions src/xlf/Resources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../Resources.resx">
<body>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A comma separated list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A comma separated list of relative file or folder paths to exclude from formatting.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting">
<source>A list of relative file or folder paths to exclude from formatting.</source>
<target state="new">A list of relative file or folder paths to exclude from formatting.</target>
<note />
</trans-unit>
<trans-unit id="A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<trans-unit id="A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty">
<source>A list of relative file or folder paths to include in formatting. All files are formatted if empty.</source>
<target state="new">A list of relative file or folder paths to include in formatting. All files are formatted if empty.</target>
<note />
</trans-unit>
<trans-unit id="Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory">
Expand Down
Loading