Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ nuget-license [options]
| `-mapping`, `--licenseurl-to-license-mappings <FILE>` | JSON dictionary mapping license URLs to license types. See [docs/licenseurl-mappings-json.md](docs/licenseurl-mappings-json.md). |
| `-override`, `--override-package-information <FILE>` | JSON list to override package/license info. See [docs/override-package-json.md](docs/override-package-json.md). |
| `-d`, `--license-information-download-location <FOLDER>` | Download all license files to the specified folder. |
| `-o`, `--output <TYPE>` | Output format: `Table`, `Json`, or `JsonPretty` (default: Table). |
| `-o`, `--output <TYPE>` | Output format: `Table`, `Markdown`, `Json` or `JsonPretty` (default: Table). |
| `-err`, `--error-only` | Only show validation errors. |
| `-include-ignored`, `--include-ignored-packages` | Include ignored packages in output. |
| `-exclude-projects`, `--exclude-projects-matching <PATTERN\|FILE>` | Exclude projects by name or pattern (supports wildcards or JSON file). See [docs/exclude-projects-json.md](docs/exclude-projects-json.md). |
Expand Down
6 changes: 4 additions & 2 deletions src/NuGetUtility/Output/Table/TableOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public class TableOutputFormatter : IOutputFormatter
{
private readonly bool _printErrorsOnly;
private readonly bool _skipIgnoredPackages;
private readonly bool _printMarkdown;

public TableOutputFormatter(bool printErrorsOnly, bool skipIgnoredPackages)
public TableOutputFormatter(bool printErrorsOnly, bool skipIgnoredPackages, bool printMarkdown = false)
{
_printErrorsOnly = printErrorsOnly;
_skipIgnoredPackages = skipIgnoredPackages;
_printMarkdown = printMarkdown;
}

public async Task Write(Stream stream, IList<LicenseValidationResult> results)
Expand Down Expand Up @@ -52,7 +54,7 @@ public async Task Write(Stream stream, IList<LicenseValidationResult> results)

ColumnDefinition[] relevantColumns = columnDefinitions.Where(c => c.Enabled).ToArray();
await TablePrinterExtensions
.Create(stream, relevantColumns.Select(d => d.Title))
.Create(stream, relevantColumns.Select(d => d.Title), _printMarkdown)
.FromValues(
results,
license => relevantColumns.Select(d => d.PropertyAccessor(license)))
Expand Down
11 changes: 8 additions & 3 deletions src/NuGetUtility/Output/Table/TablePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public class TablePrinter
private readonly List<string[][]> _rows = new List<string[][]>();
private readonly Stream _stream;
private readonly string[] _titles;
private readonly bool _printMarkdown;

public TablePrinter(Stream stream, IEnumerable<string> titles)
public TablePrinter(Stream stream, IEnumerable<string> titles, bool printMarkdown)
{
_stream = stream;
_titles = titles.ToArray();
_lengths = _titles.Select(t => t.Length).ToArray();
_printMarkdown = printMarkdown;
}

public void AddRow(object?[] row)
Expand Down Expand Up @@ -89,11 +91,14 @@ private async Task WriteRow(string[] values, TextWriter writer)

private async Task WriteSeparator(TextWriter writer)
{
string startOfLine = _printMarkdown ? "| " : "+-";
char endOfColumn = _printMarkdown ? ' ' : '-';
string endOfLine = _printMarkdown ? "|" : "+";
foreach (int l in _lengths)
{
await writer.WriteAsync("+-" + new string('-', l) + '-');
await writer.WriteAsync(startOfLine + new string('-', l) + endOfColumn);
}
await writer.WriteLineAsync("+");
await writer.WriteLineAsync(endOfLine);
}
}
}
6 changes: 3 additions & 3 deletions src/NuGetUtility/Output/Table/TablePrinterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ internal static class TablePrinterExtensions
{
public static TablePrinter Create(Stream stream, params string[] headings)
{
return new TablePrinter(stream, headings);
return new TablePrinter(stream, headings, false);
}
public static TablePrinter Create(Stream stream, IEnumerable<string> headings)
public static TablePrinter Create(Stream stream, IEnumerable<string> headings, bool printMarkdown)
{
return new TablePrinter(stream, headings);
return new TablePrinter(stream, headings, printMarkdown);
}

public static TablePrinter FromValues<T>(this TablePrinter printer,
Expand Down
3 changes: 2 additions & 1 deletion src/NuGetUtility/OutputType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum OutputType
{
Table,
Json,
JsonPretty
JsonPretty,
Markdown
}
}
1 change: 1 addition & 0 deletions src/NuGetUtility/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ private IOutputFormatter GetOutputFormatter()
OutputType.Json => new JsonOutputFormatter(false, ReturnErrorsOnly, !IncludeIgnoredPackages),
OutputType.JsonPretty => new JsonOutputFormatter(true, ReturnErrorsOnly, !IncludeIgnoredPackages),
OutputType.Table => new TableOutputFormatter(ReturnErrorsOnly, !IncludeIgnoredPackages),
OutputType.Markdown => new TableOutputFormatter(ReturnErrorsOnly, !IncludeIgnoredPackages, printMarkdown: true),
_ => throw new ArgumentOutOfRangeException($"{OutputType} not supported")
};
}
Expand Down
Loading
Loading