Skip to content

Commit

Permalink
Merge pull request #482 from WildernessLabs/folder_list
Browse files Browse the repository at this point in the history
Folder list fixes
  • Loading branch information
ctacke authored Feb 18, 2024
2 parents 979f9c9 + 1b2add5 commit a5faa67
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CliFx.Attributes;
using Microsoft.Extensions.Logging;
using System.Linq;

namespace Meadow.CLI.Commands.DeviceManagement;

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

private const string MeadowRootFolder = "meadow0";

[CommandOption("verbose", 'v', IsRequired = false)]
public bool Verbose { get; init; }

Expand All @@ -33,6 +36,14 @@ protected override async ValueTask ExecuteCommand()
{
Folder += "/";
}
if (Folder.StartsWith('/') == false)
{
Folder += "/";
}
if (Folder.Contains(MeadowRootFolder) == false)
{
Folder += $"/{MeadowRootFolder}";
}

Logger?.LogInformation($"Getting file list from '{Folder}'...");
}
Expand All @@ -41,14 +52,20 @@ protected override async ValueTask ExecuteCommand()
Logger?.LogInformation($"Getting file list...");
}

var files = await connection.Device.GetFileList(Folder ?? "/meadow0/", Verbose, CancellationToken);
var files = await connection.Device.GetFileList(Folder ?? $"/{MeadowRootFolder}/", Verbose, CancellationToken);

if (files == null || files.Length == 0)
{
Logger?.LogInformation($"No files found");
}
else
{
files = files.OrderBy(file =>
{
string prefix = file.IsDirectory ? "0" : "1";
return $"{prefix}_{file.Name}";
}).ToArray();

if (Verbose)
{
var longestFileName = files.Select(x => x.Name.Length)
Expand Down Expand Up @@ -93,7 +110,7 @@ protected override async ValueTask ExecuteCommand()
{
foreach (var file in files)
{
Logger?.LogInformation(file.Name);
Logger?.LogInformation(file.Name + (file.IsDirectory?" [folder]":string.Empty));
}

Logger?.LogInformation($"\t{files.Length} file(s)");
Expand Down
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Meadow.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Authors>Wilderness Labs, Inc</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2.0.6</PackageVersion>
<PackageVersion>2.0.7</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.CLI/</PackageProjectUrl>
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.CLI</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace Meadow.CLI
{
public static class Constants
{
public const string CLI_VERSION = "2.0.6.0";
public const string CLI_VERSION = "2.0.7.0";
}
}

0 comments on commit a5faa67

Please sign in to comment.