Skip to content

Commit

Permalink
cleanup verbose output
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Feb 18, 2024
1 parent 71b7012 commit 4d8f1d8
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CliFx.Attributes;
using Microsoft.Extensions.Logging;
using System.Linq;

namespace Meadow.CLI.Commands.DeviceManagement;

Expand All @@ -10,6 +9,7 @@ public class FileListCommand : BaseDeviceCommand<FileListCommand>
public const int FileSystemBlockSize = 4096;

private const string MeadowRootFolder = "meadow0";
private const string FolderLabel = "[folder]";

[CommandOption("verbose", 'v', IsRequired = false)]
public bool Verbose { get; init; }
Expand Down Expand Up @@ -81,19 +81,27 @@ protected override async ValueTask ExecuteCommand()
totalBlocksUsed += ((file.Size ?? 0) / FileSystemBlockSize) + 1;

var line = $"{file.Name.PadRight(longestFileName)}";
line = $"{line}\t{file.Crc:x8}";

if (file.Size > 1000000)
if(file.IsDirectory)
{
line = $"{line}\t{file.Size / 1000000d,7:0.0} MB ";
}
else if (file.Size > 1000)
{
line = $"{line}\t{file.Size / 1000,7:0} kB ";
line = $"{line}\t{FolderLabel}";
}
else
{
line = $"{line}\t{file.Size,7} bytes";
line = $"{line}\t{file.Crc:x8}";

if (file.Size > 1000000)
{
line = $"{line}\t{file.Size / 1000000d,7:0.0} MB ";
}
else if (file.Size > 1000)
{
line = $"{line}\t{file.Size / 1000,7:0} kB ";
}
else
{
line = $"{line}\t{file.Size,7} bytes";
}
}

Logger?.LogInformation(line);
Expand All @@ -110,7 +118,7 @@ protected override async ValueTask ExecuteCommand()
{
foreach (var file in files)
{
Logger?.LogInformation(file.Name + (file.IsDirectory?" [folder]":string.Empty));
Logger?.LogInformation(file.Name + (file.IsDirectory?FolderLabel:string.Empty));
}

Logger?.LogInformation($"\t{files.Length} file(s)");
Expand Down

0 comments on commit 4d8f1d8

Please sign in to comment.