mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
116 lines
3.8 KiB
C#
116 lines
3.8 KiB
C#
// /***************************************************************************
|
|
// Aaru Data Preservation Suite
|
|
// ----------------------------------------------------------------------------
|
|
//
|
|
// Filename : ListNamespaces.cs
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
//
|
|
// Component : Commands.
|
|
//
|
|
// --[ Description ] ----------------------------------------------------------
|
|
//
|
|
// Lists all options supported by read-only filesystems.
|
|
//
|
|
// --[ License ] --------------------------------------------------------------
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
//
|
|
// ----------------------------------------------------------------------------
|
|
// Copyright © 2011-2025 Natalia Portillo
|
|
// ****************************************************************************/
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Aaru.CommonTypes;
|
|
using Aaru.CommonTypes.Enums;
|
|
using Aaru.CommonTypes.Interfaces;
|
|
using Aaru.Console;
|
|
using Aaru.Core;
|
|
using Aaru.Localization;
|
|
using Spectre.Console;
|
|
using Spectre.Console.Cli;
|
|
|
|
namespace Aaru.Commands;
|
|
|
|
sealed class ListNamespacesCommand : Command<ListNamespacesCommand.Settings>
|
|
{
|
|
const string MODULE_NAME = "List-Namespaces command";
|
|
|
|
public override int Execute(CommandContext context, Settings settings)
|
|
{
|
|
MainClass.PrintCopyright();
|
|
|
|
if(settings.Debug)
|
|
{
|
|
IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings
|
|
{
|
|
Out = new AnsiConsoleOutput(System.Console.Error)
|
|
});
|
|
|
|
AaruConsole.DebugWriteLineEvent += (format, objects) =>
|
|
{
|
|
if(objects is null)
|
|
stderrConsole.MarkupLine(format);
|
|
else
|
|
stderrConsole.MarkupLine(format, objects);
|
|
};
|
|
|
|
AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); };
|
|
}
|
|
|
|
if(settings.Verbose)
|
|
{
|
|
AaruConsole.WriteEvent += (format, objects) =>
|
|
{
|
|
if(objects is null)
|
|
AnsiConsole.Markup(format);
|
|
else
|
|
AnsiConsole.Markup(format, objects);
|
|
};
|
|
}
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug);
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "--verbose={0}", settings.Verbose);
|
|
Statistics.AddCommand("list-namespaces");
|
|
|
|
PluginRegister plugins = PluginRegister.Singleton;
|
|
|
|
foreach(IReadOnlyFilesystem fs in plugins.ReadOnlyFilesystems.Values)
|
|
{
|
|
if(fs?.Namespaces is null) continue;
|
|
|
|
Table table = new()
|
|
{
|
|
Title = new TableTitle(string.Format(UI.Namespaces_for_0, fs.Name))
|
|
};
|
|
|
|
table.AddColumn(UI.Title_Namespace);
|
|
table.AddColumn(UI.Title_Description);
|
|
|
|
foreach(KeyValuePair<string, string> @namespace in fs.Namespaces.OrderBy(t => t.Key))
|
|
table.AddRow(@namespace.Key, @namespace.Value);
|
|
|
|
AnsiConsole.Write(table);
|
|
AaruConsole.WriteLine();
|
|
}
|
|
|
|
return (int)ErrorNumber.NoError;
|
|
}
|
|
|
|
#region Nested type: Settings
|
|
|
|
public class Settings : BaseSettings {}
|
|
|
|
#endregion
|
|
} |