Skip to content

Commit

Permalink
Conditionally include Project column and value into Markdown output
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsiersma committed Oct 27, 2023
1 parent 4a25dc5 commit d4bcabe
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,11 +1139,15 @@ public void PrintLicenses(List<LibraryInfo> libraries)
if (!libraries.Any()) { return; }

WriteOutput(Environment.NewLine + "References:", logLevel: LogLevel.Always);
WriteOutput(libraries.ToStringTable(new[] { "Reference", "Version", "License Type", "License" }, false,
a => a.PackageName ?? "---",
a => a.PackageVersion ?? "---",
a => a.LicenseType ?? "---",
a => a.LicenseUrl ?? "---"), logLevel: LogLevel.Always);
var columns = _packageOptions.IncludeProjectFile
? StandardMdColumns.Append("Project").ToArray()
: StandardMdColumns;

var valueSelectors = _packageOptions.IncludeProjectFile
? StandardMdValueSelectors.Append(a => a.Projects ?? "---").ToArray()
: StandardMdValueSelectors;

WriteOutput(libraries.ToStringTable(columns, false, valueSelectors), logLevel: LogLevel.Always);
}

public void SaveAsJson(List<LibraryInfo> libraries)
Expand Down Expand Up @@ -1198,17 +1202,31 @@ public void SaveAsTextFile(List<LibraryInfo> libraries)
File.WriteAllText(GetOutputFilename("licenses.txt"), sb.ToString());
}

private static readonly string[] StandardMdColumns = { "Reference", "Version", "License Type", "License" };

private static readonly Func<LibraryInfo, object>[] StandardMdValueSelectors =
{
a => a.PackageName ?? "---",
a => a.PackageVersion ?? "---",
a => a.LicenseType ?? "---",
a => a.LicenseUrl ?? "---"
};

public void SaveAsMarkdown(List<LibraryInfo> libraries)
{
if (libraries is null) { throw new ArgumentNullException(nameof(libraries)); }
if (libraries is null) { throw new ArgumentNullException(nameof(libraries)); }t

Check failure on line 1217 in src/Methods.cs

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

; expected

Check failure on line 1217 in src/Methods.cs

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

; expected

Check failure on line 1217 in src/Methods.cs

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

; expected

Check failure on line 1217 in src/Methods.cs

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

; expected

Check failure on line 1217 in src/Methods.cs

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

; expected

Check failure on line 1217 in src/Methods.cs

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

; expected

Check failure on line 1217 in src/Methods.cs

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

; expected

Check failure on line 1217 in src/Methods.cs

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

; expected
if (!libraries.Any()) { return; }

WriteOutput(Environment.NewLine + "References:", logLevel: LogLevel.Always);
var output = (libraries.ToStringTable(new[] { "Reference", "Version", "License Type", "License" }, true,
a => a.PackageName ?? "---",
a => a.PackageVersion ?? "---",
a => a.LicenseType ?? "---",
a => a.LicenseUrl ?? "---"), logLevel: LogLevel.Always);
var columns = _packageOptions.IncludeProjectFile
? StandardMdColumns.Append("Project").ToArray()
: StandardMdColumns;

var valueSelectors = _packageOptions.IncludeProjectFile
? StandardMdValueSelectors.Append(a => a.Projects ?? "---").ToArray()
: StandardMdValueSelectors;

var output = (libraries.ToStringTable(columns, true, valueSelectors), logLevel: LogLevel.Always);

File.WriteAllText(GetOutputFilename("licenses.md"), output.Item1);
}
Expand Down

0 comments on commit d4bcabe

Please sign in to comment.