Skip to content

Commit

Permalink
(GH-47) (GH-48) Add support for specifying the log file and log level…
Browse files Browse the repository at this point in the history
… for DocFxMetadata
  • Loading branch information
pascalberger committed May 15, 2017
1 parent 4763548 commit a8bc79a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Cake.DocFx.Tests/Cake.DocFx.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
<Compile Include="Init\DocFxInitRunnerFixture.cs" />
<Compile Include="Init\DocFxInitRunnerTests.cs" />
<Compile Include="ExceptionAssertExtensions.cs" />
<Compile Include="Metadata\DocFxMetadataRunnerFixture.cs" />
<Compile Include="Metadata\DocFxMetadataRunnerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions src/Cake.DocFx.Tests/Metadata/DocFxMetadataRunnerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Cake.Core.IO;
using Cake.DocFx.Metadata;

namespace Cake.DocFx.Tests.Metadata
{
internal sealed class DocFxMetadataRunnerFixture : DocFxFixture<DocFxMetadataSettings>
{
public DocFxMetadataRunnerFixture()
{
}

protected override void RunTool()
{
var tool = new DocFxMetadataRunner(FileSystem, Environment, ProcessRunner, Tools);
tool.Run(Settings);
}
}
}
62 changes: 62 additions & 0 deletions src/Cake.DocFx.Tests/Metadata/DocFxMetadataRunnerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Xunit;

namespace Cake.DocFx.Tests.Metadata
{
public class DocFxMetadataRunnerTests
{
public sealed class TheRunMethod
{
[Fact]
public void Should_Add_LogPath_To_Arguments_If_Set()
{
// Given
var fixture = new DocFxMetadataRunnerFixture
{
Settings = { LogPath = @"c:\temp\docfx.log" }
};

// When
var result = fixture.Run();

// Then
Assert.Equal("metadata -l \"c:/temp/docfx.log\"", result.Args);
}

[Theory]
[InlineData(DocFxLogLevel.Error, "Error")]
[InlineData(DocFxLogLevel.Warning, "Warning")]
[InlineData(DocFxLogLevel.Info, "Info")]
[InlineData(DocFxLogLevel.Verbose, "Verbose")]
public void Should_Add_LogLevel_To_Arguments_If_Set(DocFxLogLevel logLevel, string expectedLevel)
{
// Given
var fixture = new DocFxMetadataRunnerFixture
{
Settings = { LogLevel = logLevel }
};

// When
var result = fixture.Run();

// Then
Assert.Equal("metadata --logLevel \"" + expectedLevel + "\"", result.Args);
}

[Fact]
public void Should_Not_Add_LogLevel_To_Arguments_If_Default()
{
// Given
var fixture = new DocFxMetadataRunnerFixture
{
Settings = { LogLevel = DocFxLogLevel.Default }
};

// When
var result = fixture.Run();

// Then
Assert.Equal("metadata", result.Args);
}
}
}
}
2 changes: 2 additions & 0 deletions src/Cake.DocFx/Build/DocFxBuildRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private ProcessArgumentBuilder GetArguments(FilePath configFile, DocFxBuildSetti
if (configFile != null)
builder.Append("\"{0}\"", configFile.FullPath);

#region DupFinder Exclusion
if (settings.OutputPath != null)
builder.Append("-o \"{0}\"", settings.OutputPath.FullPath);

Expand All @@ -54,6 +55,7 @@ private ProcessArgumentBuilder GetArguments(FilePath configFile, DocFxBuildSetti

if (settings.LogLevel != DocFxLogLevel.Default)
builder.Append("--logLevel \"{0}\"", settings.LogLevel);
#endregion

if (settings.TemplateFolder != null)
builder.Append("-t \"{0}\"", settings.TemplateFolder.FullPath);
Expand Down
8 changes: 8 additions & 0 deletions src/Cake.DocFx/Metadata/DocFxMetadataRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ private ProcessArgumentBuilder GetArguments(DocFxMetadataSettings settings)
if (settings.Projects != null && settings.Projects.Any())
builder.Append(string.Join(",", settings.Projects.Select(val => val.FullPath)));

#region DupFinder Exclusion
if (settings.OutputPath != null)
builder.Append("-o \"{0}\"", settings.OutputPath.FullPath);

if (settings.LogPath != null)
builder.Append("-l \"{0}\"", settings.LogPath.FullPath);

if (settings.LogLevel != DocFxLogLevel.Default)
builder.Append("--logLevel \"{0}\"", settings.LogLevel);
#endregion

return builder;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/Cake.DocFx/Metadata/DocFxMetadataSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@ public class DocFxMetadataSettings : ToolSettings
/// Gets or sets the output folder. The default is api, and is configured in the 'metadata' section of docfx.json.
/// </summary>
public DirectoryPath OutputPath { get; set; }

/// <summary>
/// Gets or sets the path and file name where the log file generated by DocFx will be saved.
/// </summary>
public FilePath LogPath { get; set; }

/// <summary>
/// Gets or sets to which log level will be logged.
/// </summary>
public DocFxLogLevel LogLevel { get; set; }
}
}

0 comments on commit a8bc79a

Please sign in to comment.