Skip to content

Commit

Permalink
all working!
Browse files Browse the repository at this point in the history
  • Loading branch information
santisq committed Dec 17, 2024
1 parent db688a6 commit e068404
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/PowerShellKusto/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace PowerShellKusto;

internal static class Extensions
{
internal static DataTable ToDataTable(this IDataReader reader) => reader.ToDataSet().Tables[0];

internal static string ToCsvString(this IDataReader reader, bool includeHeaders = true)
{
using MemoryStream mem = new();
Expand Down
14 changes: 10 additions & 4 deletions src/PowerShellKusto/KustoReaderCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ public abstract class KustoReaderCommandBase : KustoCommandBase, IDynamicParamet

private DynamicParamExcludeHeader? _excludeHeaderParam;

private string Title { get => _titleParam!.Title; }
private string Title
{
get => _titleParam?.Title ?? string.Empty;
}

private SwitchParameter ExcludeHeaders { get => _excludeHeaderParam!.ExcludeHeaders; }
private bool ExcludeHeaders
{
get => _excludeHeaderParam is { ExcludeHeaders.IsPresent: not true };
}

[Parameter(Position = 2)]
public OutputType OutputType { get; set; } = OutputType.PSObject;
Expand Down Expand Up @@ -46,11 +52,11 @@ protected void HandleReader(IDataReader reader)
return;

case OutputType.Csv:
WriteObject(reader.ToCsvString(!ExcludeHeaders.IsPresent));
WriteObject(reader.ToCsvString(ExcludeHeaders));
return;

case OutputType.DataTable:
WriteObject(reader.ToDataSet().Tables[0]);
WriteObject(reader.ToDataTable());
return;

case OutputType.Html:
Expand Down

0 comments on commit e068404

Please sign in to comment.