Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally include Project column and value into Markdown output #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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
Loading