From bb0dcd0d86b576ffdca885f92257186caef025fb Mon Sep 17 00:00:00 2001 From: "Dylan R. E. Moonfire" Date: Sat, 2 Apr 2022 18:38:49 -0500 Subject: [PATCH] refactor!: moved table services into a dedicated assembly --- .editorconfig | 198 +++++++++--------- .prettierignore | 2 + MfGames.ToolBuilder.sln | 15 ++ README.md | 22 +- TASKS.md | 5 - scripts/README.md | 4 + scripts/format.sh | 6 + .../MfGames.ToolBuilder.Tables.csproj | 39 ++++ .../TableFormatType.cs | 0 .../TableToolService.cs | 12 +- .../Extensions/StringCliExtensions.cs | 4 +- .../MfGames.ToolBuilder.csproj | 42 ++-- .../MfGames.ToolBuilder.Tests.csproj | 1 + .../SampleToolTests.cs | 4 +- tests/SampleTool/SampleTool.csproj | 1 + 15 files changed, 218 insertions(+), 137 deletions(-) delete mode 100644 TASKS.md create mode 100644 src/MfGames.ToolBuilder.Tables/MfGames.ToolBuilder.Tables.csproj rename src/{MfGames.ToolBuilder/Tables => MfGames.ToolBuilder.Tables}/TableFormatType.cs (100%) rename src/{MfGames.ToolBuilder/Tables => MfGames.ToolBuilder.Tables}/TableToolService.cs (97%) diff --git a/.editorconfig b/.editorconfig index 2b7d34d..819c8e1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,120 +3,120 @@ root = true [*] -charset=utf-8 +charset = utf-8 end_of_line = lf -insert_final_newline=true -indent_style=space -indent_size=4 +insert_final_newline = true +indent_style = space +indent_size = 4 # Microsoft .NET properties -csharp_new_line_before_members_in_object_initializers=false -csharp_preferred_modifier_order=public, private, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async:suggestion -csharp_space_after_cast=false -csharp_style_var_elsewhere=false:hint -csharp_style_var_for_built_in_types=false:hint -csharp_style_var_when_type_is_apparent=true:hint -csharp_preserve_single_line_statements=false -csharp_preserve_single_line_blocks=true -dotnet_style_predefined_type_for_locals_parameters_members=true:hint -dotnet_style_predefined_type_for_member_access=true:hint -dotnet_style_qualification_for_event=true:hint -dotnet_style_qualification_for_field=true:hint -dotnet_style_qualification_for_method=true:hint -dotnet_style_qualification_for_property=true:hint -dotnet_style_require_accessibility_modifiers=for_non_interface_members:hint +csharp_new_line_before_members_in_object_initializers = false +csharp_preferred_modifier_order = public, private, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async:suggestion +csharp_space_after_cast = false +csharp_style_var_elsewhere = false:hint +csharp_style_var_for_built_in_types = false:hint +csharp_style_var_when_type_is_apparent = true:hint +csharp_preserve_single_line_statements = false +csharp_preserve_single_line_blocks = true +dotnet_style_predefined_type_for_locals_parameters_members = true:hint +dotnet_style_predefined_type_for_member_access = true:hint +dotnet_style_qualification_for_event = true:hint +dotnet_style_qualification_for_field = true:hint +dotnet_style_qualification_for_method = true:hint +dotnet_style_qualification_for_property = true:hint +dotnet_style_require_accessibility_modifiers = for_non_interface_members:hint # ReSharper properties -resharper_alignment_tab_fill_style=optimal_fill -resharper_apply_on_completion=true -resharper_blank_lines_after_control_transfer_statements=1 -resharper_blank_lines_around_single_line_auto_property=1 -resharper_blank_lines_around_single_line_property=1 -resharper_blank_lines_before_single_line_comment=1 -resharper_blank_lines_between_using_groups=1 -resharper_braces_for_for=required -resharper_braces_for_foreach=required -resharper_braces_for_ifelse=required -resharper_braces_for_while=required -resharper_can_use_global_alias=false -resharper_csharp_blank_lines_around_single_line_field=1 -resharper_csharp_blank_lines_around_single_line_invocable=1 -resharper_csharp_indent_style=tab -resharper_csharp_insert_final_newline=true -resharper_csharp_keep_blank_lines_in_code=1 -resharper_csharp_keep_blank_lines_in_declarations=1 -resharper_csharp_new_line_before_while=true -resharper_csharp_use_indent_from_vs=false -resharper_csharp_wrap_arguments_style=chop_if_long -resharper_csharp_wrap_extends_list_style=chop_if_long -resharper_csharp_wrap_parameters_style=chop_if_long -resharper_css_insert_final_newline=false -resharper_enforce_line_ending_style=true -resharper_html_insert_final_newline=false -resharper_indent_nested_fixed_stmt=true -resharper_js_indent_style=tab -resharper_js_insert_final_newline=true -resharper_js_keep_blank_lines_in_code=1 -resharper_js_stick_comment=false -resharper_js_use_indent_from_vs=false -resharper_js_wrap_before_binary_opsign=true -resharper_js_wrap_chained_method_calls=chop_if_long -resharper_keep_blank_lines_between_declarations=1 -resharper_min_blank_lines_after_imports=1 -resharper_place_attribute_on_same_line=False -resharper_place_constructor_initializer_on_same_line=false -resharper_place_type_constraints_on_same_line=false -resharper_protobuf_insert_final_newline=false -resharper_qualified_using_at_nested_scope=true -resharper_resx_insert_final_newline=false -resharper_space_within_single_line_array_initializer_braces=true -resharper_use_indents_from_main_language_in_file=false -resharper_vb_insert_final_newline=false -resharper_wrap_after_declaration_lpar=true -resharper_wrap_after_invocation_lpar=true -resharper_wrap_before_extends_colon=true -resharper_wrap_before_first_type_parameter_constraint=true -resharper_wrap_before_type_parameter_langle=true -resharper_xmldoc_indent_child_elements=ZeroIndent -resharper_xmldoc_indent_text=ZeroIndent -resharper_xmldoc_insert_final_newline=false -resharper_xml_insert_final_newline=false +resharper_alignment_tab_fill_style = optimal_fill +resharper_apply_on_completion = true +resharper_blank_lines_after_control_transfer_statements = 1 +resharper_blank_lines_around_single_line_auto_property = 1 +resharper_blank_lines_around_single_line_property = 1 +resharper_blank_lines_before_single_line_comment = 1 +resharper_blank_lines_between_using_groups = 1 +resharper_braces_for_for = required +resharper_braces_for_foreach = required +resharper_braces_for_ifelse = required +resharper_braces_for_while = required +resharper_can_use_global_alias = false +resharper_csharp_blank_lines_around_single_line_field = 1 +resharper_csharp_blank_lines_around_single_line_invocable = 1 +resharper_csharp_indent_style = tab +resharper_csharp_insert_final_newline = true +resharper_csharp_keep_blank_lines_in_code = 1 +resharper_csharp_keep_blank_lines_in_declarations = 1 +resharper_csharp_new_line_before_while = true +resharper_csharp_use_indent_from_vs = false +resharper_csharp_wrap_arguments_style = chop_if_long +resharper_csharp_wrap_extends_list_style = chop_if_long +resharper_csharp_wrap_parameters_style = chop_if_long +resharper_css_insert_final_newline = false +resharper_enforce_line_ending_style = true +resharper_html_insert_final_newline = false +resharper_indent_nested_fixed_stmt = true +resharper_js_indent_style = tab +resharper_js_insert_final_newline = true +resharper_js_keep_blank_lines_in_code = 1 +resharper_js_stick_comment = false +resharper_js_use_indent_from_vs = false +resharper_js_wrap_before_binary_opsign = true +resharper_js_wrap_chained_method_calls = chop_if_long +resharper_keep_blank_lines_between_declarations = 1 +resharper_min_blank_lines_after_imports = 1 +resharper_place_attribute_on_same_line = False +resharper_place_constructor_initializer_on_same_line = false +resharper_place_type_constraints_on_same_line = false +resharper_protobuf_insert_final_newline = false +resharper_qualified_using_at_nested_scope = true +resharper_resx_insert_final_newline = false +resharper_space_within_single_line_array_initializer_braces = true +resharper_use_indents_from_main_language_in_file = false +resharper_vb_insert_final_newline = false +resharper_wrap_after_declaration_lpar = true +resharper_wrap_after_invocation_lpar = true +resharper_wrap_before_extends_colon = true +resharper_wrap_before_first_type_parameter_constraint = true +resharper_wrap_before_type_parameter_langle = true +resharper_xmldoc_indent_child_elements = ZeroIndent +resharper_xmldoc_indent_text = ZeroIndent +resharper_xmldoc_insert_final_newline = false +resharper_xml_insert_final_newline = false # ReSharper inspection severities -resharper_check_namespace_highlighting=none -resharper_convert_to_auto_property_highlighting=none -resharper_localizable_element_highlighting=none -resharper_redundant_comma_in_attribute_list_highlighting=none -resharper_redundant_comma_in_enum_declaration_highlighting=none -resharper_redundant_comma_in_initializer_highlighting=none -resharper_string_compare_to_is_culture_specific_highlighting=none -resharper_string_index_of_is_culture_specific_1_highlighting=none -resharper_use_null_propagation_highlighting=none -resharper_use_object_or_collection_initializer_highlighting=hint -resharper_use_string_interpolation_highlighting=hint +resharper_check_namespace_highlighting = none +resharper_convert_to_auto_property_highlighting = none +resharper_localizable_element_highlighting = none +resharper_redundant_comma_in_attribute_list_highlighting = none +resharper_redundant_comma_in_enum_declaration_highlighting = none +resharper_redundant_comma_in_initializer_highlighting = none +resharper_string_compare_to_is_culture_specific_highlighting = none +resharper_string_index_of_is_culture_specific_1_highlighting = none +resharper_use_null_propagation_highlighting = none +resharper_use_object_or_collection_initializer_highlighting = hint +resharper_use_string_interpolation_highlighting = hint # Matches the exact files either package.json or .travis.yml [{package.json,.travis.yml}] -indent_style=space -indent_size=2 -tab_width=2 +indent_style = space +indent_size = 2 +tab_width = 2 [*.{cs,js,json,jsx,proto,resjson,ts,tsx}] -indent_style=space -indent_size=4 -tab_width=4 +indent_style = space +indent_size = 4 +tab_width = 4 [*.{asax,ascx,aspx,cshtml,css,htm,html,master,razor,skin,vb,xaml,xamlx,xoml}] -indent_style=space -indent_size=4 -tab_width=4 +indent_style = space +indent_size = 4 +tab_width = 4 [*.{appxmanifest,build,config,csproj,dbml,discomap,dtd,jsproj,lsproj,njsproj,nuspec,proj,props,resw,resx,StyleCop,targets,tasks,vbproj,xml,xsd}] -indent_style=space -indent_size=2 -tab_width=2 +indent_style = space +indent_size = 2 +tab_width = 2 [*.proto] -indent_style=space -indent_size=2 -tab_width=2 +indent_style = space +indent_size = 2 +tab_width = 2 diff --git a/.prettierignore b/.prettierignore index 56c7a40..f1a0e24 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,3 +4,5 @@ flake.* node_modules/ .direnv/ .config/ +obj/ +bin/ diff --git a/MfGames.ToolBuilder.sln b/MfGames.ToolBuilder.sln index 1c87b94..4cd36b3 100644 --- a/MfGames.ToolBuilder.sln +++ b/MfGames.ToolBuilder.sln @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4CE102F8 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MfGames.ToolBuilder.Tests", "tests\MfGames.ToolBuilder.Tests\MfGames.ToolBuilder.Tests.csproj", "{77DDD61F-AF57-4AE7-A2A8-08C61A630A9A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MfGames.ToolBuilder.Tables", "src\MfGames.ToolBuilder.Tables\MfGames.ToolBuilder.Tables.csproj", "{1124D139-7557-46C1-906A-39E939E6FFF9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,10 +64,23 @@ Global {77DDD61F-AF57-4AE7-A2A8-08C61A630A9A}.Release|x64.Build.0 = Release|Any CPU {77DDD61F-AF57-4AE7-A2A8-08C61A630A9A}.Release|x86.ActiveCfg = Release|Any CPU {77DDD61F-AF57-4AE7-A2A8-08C61A630A9A}.Release|x86.Build.0 = Release|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Debug|x64.ActiveCfg = Debug|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Debug|x64.Build.0 = Debug|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Debug|x86.ActiveCfg = Debug|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Debug|x86.Build.0 = Debug|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Release|Any CPU.Build.0 = Release|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Release|x64.ActiveCfg = Release|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Release|x64.Build.0 = Release|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Release|x86.ActiveCfg = Release|Any CPU + {1124D139-7557-46C1-906A-39E939E6FFF9}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {5253E2A6-9565-45AF-92EA-1BFD3A63AC23} = {9C845D9A-B359-43B3-AE9E-B84CE945AF21} {0A12108A-9E00-41E9-8935-F4AA7D6208FB} = {4CE102F8-5C70-4696-B85F-93BB10034918} {77DDD61F-AF57-4AE7-A2A8-08C61A630A9A} = {4CE102F8-5C70-4696-B85F-93BB10034918} + {1124D139-7557-46C1-906A-39E939E6FFF9} = {9C845D9A-B359-43B3-AE9E-B84CE945AF21} EndGlobalSection EndGlobal diff --git a/README.md b/README.md index 2b53ebb..1642f87 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,27 @@ _An opinionated library for easily creating command-line tools in C#._ -ToolBuilder is a library to encapsulate the setup and running of tools, CLI components arranged with verbs (like `git`). It includes some opinionated decisions on default setup. +MfGames.ToolBuilder is a library to encapsulate the setup and running of tools, CLI components arranged with verbs (like `git`). It includes some opinionated decisions on default setup. + +## Building + +To make sure the environment is correctly set up for build: + +```sh +./scripts/setup.sh +``` + +To build the project: + +```sh +./scripts/build.sh +``` + +To test the project: + +```sh +./scripts/test.sh +``` ## Commands diff --git a/TASKS.md b/TASKS.md deleted file mode 100644 index f31aaea..0000000 --- a/TASKS.md +++ /dev/null @@ -1,5 +0,0 @@ -- [ ] Split out tables into an assembly -- [ ] Switch to GitVersion for release -- [ ] Switch to scripts instead of Node for targets -- [ ] Clean up the Gitlab setup - - [ ] Change configuration back to default diff --git a/scripts/README.md b/scripts/README.md index 6245177..f357938 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -14,6 +14,10 @@ This builds the project and creates the binaries in debug mode. This runs any required tests. +## `format.sh` + +This is used to format the code base using our standards. It matches the commands in the `lefthook` pre-commit hook. + ## `release.sh` Intended to run in a CI environment, this creates a NuGet package and publishes it. diff --git a/scripts/format.sh b/scripts/format.sh index a3386a9..fd015be 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -6,3 +6,9 @@ cd $(dirname $0)/.. # Format the .NET code dotnet format || exit 1 + +# Format using Prettier. +prettier . --write --loglevel warn + +# Format the Flake. +nixfmt flake.nix diff --git a/src/MfGames.ToolBuilder.Tables/MfGames.ToolBuilder.Tables.csproj b/src/MfGames.ToolBuilder.Tables/MfGames.ToolBuilder.Tables.csproj new file mode 100644 index 0000000..00b3670 --- /dev/null +++ b/src/MfGames.ToolBuilder.Tables/MfGames.ToolBuilder.Tables.csproj @@ -0,0 +1,39 @@ + + + + net6.0 + enable + enable + Provides a tool service for creating tools that output tabular data to the console. + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/src/MfGames.ToolBuilder/Tables/TableFormatType.cs b/src/MfGames.ToolBuilder.Tables/TableFormatType.cs similarity index 100% rename from src/MfGames.ToolBuilder/Tables/TableFormatType.cs rename to src/MfGames.ToolBuilder.Tables/TableFormatType.cs diff --git a/src/MfGames.ToolBuilder/Tables/TableToolService.cs b/src/MfGames.ToolBuilder.Tables/TableToolService.cs similarity index 97% rename from src/MfGames.ToolBuilder/Tables/TableToolService.cs rename to src/MfGames.ToolBuilder.Tables/TableToolService.cs index 8d140b6..3636bd5 100644 --- a/src/MfGames.ToolBuilder/Tables/TableToolService.cs +++ b/src/MfGames.ToolBuilder.Tables/TableToolService.cs @@ -1,14 +1,10 @@ #pragma warning disable Serilog004 // Constant MessageTemplate verifier -using System; -using System.Collections.Generic; using System.CommandLine; using System.CommandLine.Invocation; using System.CommandLine.IO; using System.Data; using System.Globalization; -using System.IO; -using System.Linq; using ConsoleTableExt; @@ -152,7 +148,7 @@ namespace MfGames.ToolBuilder.Tables .Select(x => x.ColumnName) .ToList(); - List expandedNames = tableColumns + var expandedNames = tableColumns .SelectMany(x => IsMatch(allColumns, x)) .ToList(); @@ -333,7 +329,7 @@ namespace MfGames.ToolBuilder.Tables var csv = new CsvWriter(stringWriter, configuration); foreach (DataColumn column in - this.table!.Columns.OfType()) + this.table!.Columns.OfType()) { csv.WriteField(column.ColumnName); } @@ -343,7 +339,7 @@ namespace MfGames.ToolBuilder.Tables foreach (DataRow row in this.table.AsEnumerable()) { foreach (DataColumn column in this.table.Columns - .OfType()) + .OfType()) { csv.WriteField(Convert.ToString(row[column])); } @@ -402,7 +398,7 @@ namespace MfGames.ToolBuilder.Tables TableFormatType tableFormat) { // Build the table from options. - ConsoleTableBuilder builder = ConsoleTableBuilder.From(this.table); + var builder = ConsoleTableBuilder.From(this.table); // Figure out formatting. if (tableFormat == TableFormatType.Default) diff --git a/src/MfGames.ToolBuilder/Extensions/StringCliExtensions.cs b/src/MfGames.ToolBuilder/Extensions/StringCliExtensions.cs index 07870e5..3f2d67b 100644 --- a/src/MfGames.ToolBuilder/Extensions/StringCliExtensions.cs +++ b/src/MfGames.ToolBuilder/Extensions/StringCliExtensions.cs @@ -48,7 +48,7 @@ namespace MfGames.ToolBuilder.Extensions ICollection possible) { // Look for a direct match. - List found = possible + var found = possible .Where( x => string.Equals( x, @@ -116,7 +116,7 @@ namespace MfGames.ToolBuilder.Extensions } // Attempt a fuzzy search. - List possible = Enum.GetNames(typeof(TEnum)) + var possible = Enum.GetNames(typeof(TEnum)) .Select(e => e.ToLower()) .Where(e => e.StartsWith(input.ToLower())) .ToList(); diff --git a/src/MfGames.ToolBuilder/MfGames.ToolBuilder.csproj b/src/MfGames.ToolBuilder/MfGames.ToolBuilder.csproj index f20dbb9..d5fb0f4 100644 --- a/src/MfGames.ToolBuilder/MfGames.ToolBuilder.csproj +++ b/src/MfGames.ToolBuilder/MfGames.ToolBuilder.csproj @@ -5,24 +5,24 @@ enable A framework for easily creating command line tools using System.CommandLine, Autofac, and Serilog. - + $(NoWarn);NU5104 - - - - - - - - - - - + + + + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -35,15 +35,15 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - + + + + + + + + + diff --git a/tests/MfGames.ToolBuilder.Tests/MfGames.ToolBuilder.Tests.csproj b/tests/MfGames.ToolBuilder.Tests/MfGames.ToolBuilder.Tests.csproj index a9c4af3..177dbb2 100644 --- a/tests/MfGames.ToolBuilder.Tests/MfGames.ToolBuilder.Tests.csproj +++ b/tests/MfGames.ToolBuilder.Tests/MfGames.ToolBuilder.Tests.csproj @@ -36,6 +36,7 @@ + diff --git a/tests/MfGames.ToolBuilder.Tests/SampleToolTests.cs b/tests/MfGames.ToolBuilder.Tests/SampleToolTests.cs index 8850897..44e3bd7 100644 --- a/tests/MfGames.ToolBuilder.Tests/SampleToolTests.cs +++ b/tests/MfGames.ToolBuilder.Tests/SampleToolTests.cs @@ -35,7 +35,9 @@ namespace MfGames.ToolBuilder.Tests .WithArguments( new[] { - "run", "--project", projectFile.FullName, "--", + "run", + "--project", projectFile.FullName, + "--", "crash", }) .WithWorkingDirectory(projectFile.DirectoryName!) diff --git a/tests/SampleTool/SampleTool.csproj b/tests/SampleTool/SampleTool.csproj index de830d0..2f8c80b 100644 --- a/tests/SampleTool/SampleTool.csproj +++ b/tests/SampleTool/SampleTool.csproj @@ -10,6 +10,7 @@ +