Files
RobustToolbox/Robust.Shared/Console/Commands/VfsCommands.cs
Pieter-Jan Briers 23abb6177d Fixes for resource manager, roots and ResPath.
`ResPath.RelativeTo()` now considers non-rooted paths relative to `.`
This fixes some things like `MemoryContentRoot`'s `FindFiles()` implementation.

Fix `IContentRoot.GetEntries()` default implementation (used by all content roots except `DirLoader`) not working at all.

Made `ResourceManager.ContentGetDirectoryEntries()` report content root mount paths as directories.

Added tests for all of the above.
2023-06-03 12:23:28 +02:00

39 lines
1.1 KiB
C#

using Robust.Shared.ContentPack;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
namespace Robust.Shared.Console.Commands;
public sealed class VfsListCommand : LocalizedCommands
{
[Dependency] private readonly IResourceManager _resourceManager = default!;
public override string Command => "vfs_ls";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length > 1)
{
shell.WriteError(LocalizationManager.GetString("cmd-vfs_ls-err-args"));
return;
}
var entries = _resourceManager.ContentGetDirectoryEntries(new ResPath(args[0]));
foreach (var entry in entries)
{
shell.WriteLine(entry);
}
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var opts = CompletionHelper.ContentDirPath(args[0], _resourceManager);
return CompletionResult.FromHintOptions(opts, LocalizationManager.GetString("cmd-vfs_ls-hint-path"));
}
return CompletionResult.Empty;
}
}