-
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.
Add CLI command for formatting editorconfig file
- Loading branch information
Showing
9 changed files
with
72 additions
and
46 deletions.
There are no files selected for viewing
15 changes: 0 additions & 15 deletions
15
Sources/Kysect.Configuin.ConfigurationRoot/Configuration/ConfiguinConfiguration.cs
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
Sources/Kysect.Configuin.ConfigurationRoot/Configuration/EditorConfigApplyConfiguration.cs
This file was deleted.
Oops, something went wrong.
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
46 changes: 46 additions & 0 deletions
46
Sources/Kysect.Configuin.Console/Commands/FormatEditorconfigCommand.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,46 @@ | ||
using Kysect.CommonLib.BaseTypes.Extensions; | ||
using Kysect.Configuin.EditorConfig.DocumentModel; | ||
using Kysect.Configuin.EditorConfig.DocumentModel.Nodes; | ||
using Kysect.Configuin.EditorConfig.Formatter; | ||
using Kysect.Configuin.MsLearn; | ||
using Kysect.Configuin.MsLearn.Models; | ||
using Kysect.Configuin.RoslynModels; | ||
using Spectre.Console.Cli; | ||
using System.ComponentModel; | ||
|
||
namespace Kysect.Configuin.Console.Commands; | ||
|
||
internal sealed class FormatEditorconfigCommand( | ||
IMsLearnDocumentationInfoReader repositoryPathReader, | ||
IMsLearnDocumentationParser msLearnDocumentationParser, | ||
EditorConfigDocumentParser editorConfigDocumentParser, | ||
EditorConfigFormatter editorConfigFormatter) : Command<FormatEditorconfigCommand.Settings> | ||
{ | ||
public sealed class Settings : CommandSettings | ||
{ | ||
[Description("Path to editorconfig.")] | ||
[CommandArgument(0, "[editor config path]")] | ||
public string? EditorConfigPath { get; init; } | ||
|
||
[Description("Path to cloned MS Learn repository.")] | ||
[CommandOption("-d|--documentation")] | ||
public string? MsLearnRepositoryPath { get; init; } | ||
} | ||
|
||
public override int Execute(CommandContext context, Settings settings) | ||
{ | ||
settings.EditorConfigPath.ThrowIfNull(); | ||
settings.MsLearnRepositoryPath.ThrowIfNull(); | ||
|
||
string editorConfigContent = File.ReadAllText(settings.EditorConfigPath); | ||
string[] editorConfigContentLines = File.ReadAllLines(settings.EditorConfigPath); | ||
|
||
MsLearnDocumentationRawInfo msLearnDocumentationRawInfo = repositoryPathReader.Provide(settings.MsLearnRepositoryPath); | ||
RoslynRules roslynRules = msLearnDocumentationParser.Parse(msLearnDocumentationRawInfo); | ||
EditorConfigDocument editorConfigDocument = editorConfigDocumentParser.Parse(editorConfigContentLines); | ||
EditorConfigDocument formattedDocument = editorConfigFormatter.FormatAccordingToRuleDefinitions(editorConfigDocument, roslynRules); | ||
File.WriteAllText(settings.EditorConfigPath, formattedDocument.ToFullString()); | ||
|
||
return 0; | ||
} | ||
} |
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
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
2 changes: 2 additions & 0 deletions
2
Sources/Kysect.Configuin.EditorConfig/IDotnetConfigSettingsParser.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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
using Kysect.Configuin.EditorConfig.DocumentModel.Nodes; | ||
using Kysect.Configuin.EditorConfig.Settings; | ||
|
||
namespace Kysect.Configuin.EditorConfig; | ||
|
||
public interface IDotnetConfigSettingsParser | ||
{ | ||
DotnetConfigSettings Parse(EditorConfigDocument editorConfigDocument); | ||
IEditorConfigSetting ParseSetting(EditorConfigPropertyNode line); | ||
} |