Skip to content

Commit

Permalink
Add ability to set verbosity via command line arguments (#11)
Browse files Browse the repository at this point in the history
* Add ability to set verbosity via command line arguments
* Remove IMetalsharpFile and IMetalsharpFileCollection
* Remove tab from MetalsharpProject
* Format XML comments in MetalsharpConfiguration
  • Loading branch information
IanWold authored Aug 15, 2022
1 parent 8cefc1a commit 2209829
Show file tree
Hide file tree
Showing 23 changed files with 163 additions and 278 deletions.
3 changes: 2 additions & 1 deletion Metalsharp.Examples/Metalsharp.ExampleWebsite/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Metalsharp;
using Metalsharp.ExamplePlugin;
using Metalsharp.Logging;

new MetalsharpProject()
new MetalsharpProject(new MetalsharpConfiguration { Verbosity = LogLevel.Debug })
.AddInput("Site")
.Use<Frontmatter>()
.UseDrafts()
Expand Down
4 changes: 2 additions & 2 deletions Metalsharp.Tests/LogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static void TestOnLog(LogLevel projectLevel, LogLevel messageLevel, Acti
var wasOnLogInvoked = false;
var project = new MetalsharpProject(new MetalsharpConfiguration()
{
LogLevel = projectLevel
Verbosity = projectLevel
});

project.Log.OnLog += (_, _) => wasOnLogInvoked = true;
Expand All @@ -34,7 +34,7 @@ private static void TestOnAnyLog(LogLevel projectLevel, LogLevel messageLevel)
var wasOnAnyLogInvoked = false;
var project = new MetalsharpProject(new MetalsharpConfiguration()
{
LogLevel = projectLevel
Verbosity = projectLevel
});

project.Log.OnAnyLog += (_, _) => wasOnAnyLogInvoked = true;
Expand Down
4 changes: 2 additions & 2 deletions Metalsharp.Tests/MetalsharpFileCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class MetalsharpFileCollectionTests
[InlineData(new[] { "Dir1\\Dir2\\F1.a", "Dir1\\Dir3\\F2.a", "Dir4\\F3.a" }, "Dir1", new[] { "F1", "F2" })]
public void DescendantsOfReturnsCorrectFiles(string[] paths, string ancestorDirectory, string[] expectedFileNames)
{
var collection = new MetalsharpFileCollection<MetalsharpFile>(paths.Select(p => new MetalsharpFile("text", p)));
var collection = new MetalsharpFileCollection(paths.Select(p => new MetalsharpFile("text", p)));

foreach (var name in collection.DescendantsOf(ancestorDirectory).Select(i => i.Name))
{
Expand All @@ -23,7 +23,7 @@ public void DescendantsOfReturnsCorrectFiles(string[] paths, string ancestorDire
[InlineData(new[] { "Dir1\\Dir2\\F1.a", "Dir3\\Dir2\\F2.a", "Dir4\\F3.a" }, "Dir2", new[] { "F1", "F2" })]
public void ChildrenOfReturnsCorrectFiles(string[] paths, string parentDirectory, string[] expectedFileNames)
{
var collection = new MetalsharpFileCollection<MetalsharpFile>(paths.Select(p => new MetalsharpFile("text", p)));
var collection = new MetalsharpFileCollection(paths.Select(p => new MetalsharpFile("text", p)));

foreach (var name in collection.ChildrenOf(parentDirectory).Select(i => i.Name))
{
Expand Down
64 changes: 32 additions & 32 deletions Metalsharp.Tests/MetalsharpProjectTests.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Metalsharp.Tests/Plugins/BranchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void BranchExecutesBranchesIndependently()

new MetalsharpProject(new MetalsharpConfiguration()
{
LogLevel = Logging.LogLevel.None
Verbosity = Logging.LogLevel.None
})
.AddInput("Scenario\\Plugins")
.Branch(
Expand Down
12 changes: 6 additions & 6 deletions Metalsharp.Tests/Plugins/CollectionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CollectionsTests
[Fact]
public void CollectionsCorrectlyGroupsFiles()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None })
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None })
.AddInput("Scenario\\Directory1")
.AddInput("Scenario\\Plugins")
.AddOutput("Scenario\\Directory2\\SubDirectory1")
Expand All @@ -27,7 +27,7 @@ public void CollectionsCorrectlyGroupsFiles()
[Fact]
public void GetFilesFromCollectionReturnsCorrectFiles()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None })
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None })
.AddInput("Scenario\\Directory1")
.AddInput("Scenario\\Plugins")
.AddOutput("Scenario\\Directory2\\SubDirectory1")
Expand All @@ -42,7 +42,7 @@ public void GetFilesFromCollectionReturnsCorrectFiles()
[Fact]
public void CollectionsCorrectlyGroupsInputFiles()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None })
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None })
.AddInput("Scenario\\Directory1")
.AddInput("Scenario\\Plugins")
.UseCollections("test", file => file.Name.Contains("file"));
Expand All @@ -54,7 +54,7 @@ public void CollectionsCorrectlyGroupsInputFiles()
[Fact]
public void CollectionsCorrectlyGroupsOutputFiles()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None })
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None })
.AddOutput("Scenario\\Directory1")
.AddOutput("Scenario\\Plugins")
.UseCollections("test", file => file.Name.Contains("file"));
Expand All @@ -66,7 +66,7 @@ public void CollectionsCorrectlyGroupsOutputFiles()
[Fact]
public void GetInputFilesFromCollectionReturnsCorrectFiles()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None })
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None })
.AddInput("Scenario\\Directory1")
.AddInput("Scenario\\Plugins")
.UseCollections("test", file => file.Name.Contains("file"));
Expand All @@ -78,7 +78,7 @@ public void GetInputFilesFromCollectionReturnsCorrectFiles()
[Fact]
public void GetOutputFilesFromCollectionReturnsCorrectFiles()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None })
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None })
.AddOutput("Scenario\\Directory1")
.AddOutput("Scenario\\Plugins")
.UseCollections("test", file => file.Name.Contains("file"));
Expand Down
2 changes: 1 addition & 1 deletion Metalsharp.Tests/Plugins/DebugTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void DebugLogsAftereUse()
var didLogAfterPlugin = false;
object testMetadataValue = null;

var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None });
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None });
project
.UseDebug(i =>
{
Expand Down
6 changes: 3 additions & 3 deletions Metalsharp.Tests/Plugins/FrontmatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ public class FrontmatterTests
[Fact]
public void FrontmatterSucceedsWithoutFrontmatter()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileMarkdown.md").UseFrontmatter();
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileMarkdown.md").UseFrontmatter();

Assert.True(project.InputFiles[0].Metadata.Count == 0);
}

[Fact]
public void FrontmatterParsesJsonFrontmatter()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileJsonFrontmatter.md").UseFrontmatter();
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileJsonFrontmatter.md").UseFrontmatter();

Assert.True((bool)project.InputFiles[0].Metadata["test"]);
}

[Fact]
public void FrontmatterParsesYamlFrontmatter()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileYamlFrontmatter.md").UseFrontmatter();
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileYamlFrontmatter.md").UseFrontmatter();

Assert.True(ToBoolean(project.InputFiles[0].Metadata["test"].ToString()));
}
Expand Down
4 changes: 2 additions & 2 deletions Metalsharp.Tests/Plugins/LevellerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class LevellerTests
public void LevellerAddsLevelMetadata()
{
var file = new MetalsharpFile("", "file");
_ = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None }).AddInput(file).UseLeveller();
_ = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None }).AddInput(file).UseLeveller();

Assert.Contains(file.Metadata, m => m.Key == "level");
}

[Fact]
public void LevellerCorrectlyLevelsFiles()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None }).AddInput("Scenario\\Directory2", "").UseLeveller();
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None }).AddInput("Scenario\\Directory2", "").UseLeveller();

Assert.Equal(1, project.InputFiles.Single(f => f.Name == "file10").Metadata["level"]);
Assert.Equal(2, project.InputFiles.Single(f => f.Name == "file11").Metadata["level"]);
Expand Down
4 changes: 2 additions & 2 deletions Metalsharp.Tests/Plugins/MarkdownTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public class MarkdownTests
[Fact]
public void MarkdownGeneratesHtmlFile()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileMarkdown.md").UseMarkdown();
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileMarkdown.md").UseMarkdown();

Assert.Contains(project.OutputFiles, i => i.Extension == ".html");
}

[Fact]
public void MarkdownCopiesMetadata()
{
var project = new MetalsharpProject(new MetalsharpConfiguration() { LogLevel = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileMarkdown.md")
var project = new MetalsharpProject(new MetalsharpConfiguration() { Verbosity = Logging.LogLevel.None }).AddInput("Scenario\\Plugins\\FileMarkdown.md")
.Use(proj => proj.InputFiles.ToList().ForEach(i => i.Metadata.Add("test", true)))
.Use<Markdown>();

Expand Down
78 changes: 0 additions & 78 deletions Metalsharp/Interfaces/IMetalsharpFile.cs

This file was deleted.

59 changes: 0 additions & 59 deletions Metalsharp/Interfaces/IMetalsharpFileCollection.cs

This file was deleted.

15 changes: 9 additions & 6 deletions Metalsharp/Logging/LogLevel.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
namespace Metalsharp.Logging;
using System;

namespace Metalsharp.Logging;

/// <summary>
/// The verbosity level for log messages.
/// </summary>
[Flags]
public enum LogLevel
{
/// <summary>
/// `Debug` includes every loggable event useful when debugging.
/// </summary>
Debug = 0,
Debug = 0x0,

/// <summary>
/// `Info` includes every meaningful event while executing.
/// </summary>
Info = 1,
Info = 0x1,

/// <summary>
/// `Error` includes any events that are unexpected or may be unintended by the user.
/// </summary>
Error = 2,
Error = 0x2,

/// <summary>
/// `Fatal` includes any events that prevent continued execution.
/// </summary>
Fatal = 3,
Fatal = 0x4,

/// <summary>
/// `None` prevents any logging.
/// </summary>
None = 4,
None = 0x8,
}
3 changes: 2 additions & 1 deletion Metalsharp/Metalsharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Markdig" Version="0.30.2" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Markdig" Version="0.30.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="YamlDotNet" Version="12.0.0" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 2209829

Please sign in to comment.