refactor(cli): rename audit-log to audit-config with deprecation alias (#23 M8)

This commit is contained in:
Joseph Doherty
2026-05-20 22:02:19 -04:00
parent d40ee85e14
commit ba8ddcc032
3 changed files with 145 additions and 1 deletions

View File

@@ -4,11 +4,50 @@ using ScadaLink.Commons.Messages.Management;
namespace ScadaLink.CLI.Commands;
/// <summary>
/// The <c>scadalink audit-config</c> command group: views the configuration-change
/// audit log (the <c>IAuditService</c> trail of admin edits — distinct from the
/// centralized append-only Audit Log served by <see cref="AuditCommands"/>).
/// </summary>
/// <remarks>
/// Renamed from <c>audit-log</c> in #23 M8-T7 to avoid confusion with the new
/// <c>scadalink audit</c> group. The old <c>audit-log</c> name is retained as a
/// deprecated alias; <see cref="DeprecatedAlias"/> still resolves the full subcommand
/// tree, and <c>Program.cs</c> prints a deprecation warning when it is used.
/// </remarks>
public static class AuditLogCommands
{
/// <summary>The deprecated alias kept for backward compatibility with the old command name.</summary>
public const string DeprecatedAlias = "audit-log";
/// <summary>The deprecation warning emitted when the old <c>audit-log</c> name is used.</summary>
public const string DeprecationWarning =
"Warning: 'audit-log' is deprecated and will be removed in a future release. "
+ "Use 'audit-config' instead.";
/// <summary>
/// Writes the <see cref="DeprecationWarning"/> to <paramref name="stderr"/> when the
/// CLI was invoked via the deprecated <c>audit-log</c> command name (i.e. the first
/// argument is <see cref="DeprecatedAlias"/>). The command itself still works — it is
/// an alias of <c>audit-config</c> — so this only adds the migration warning.
/// Factored out of <c>Program.cs</c> so it is unit-testable without spawning a process.
/// </summary>
public static void WriteDeprecationWarningIfNeeded(string[] args, TextWriter stderr)
{
if (args.Length > 0
&& string.Equals(args[0], DeprecatedAlias, StringComparison.Ordinal))
{
stderr.WriteLine(DeprecationWarning);
}
}
public static Command Build(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
{
var command = new Command("audit-log") { Description = "Query audit logs" };
var command = new Command("audit-config") { Description = "Query the configuration-change audit log" };
// Backward-compatible alias for the pre-M8 `audit-log` name. The alias keeps
// full subcommand parity automatically; the deprecation warning is emitted by
// the args[0] check in Program.cs.
command.Aliases.Add(DeprecatedAlias);
command.Add(BuildQuery(urlOption, formatOption, usernameOption, passwordOption));

View File

@@ -39,5 +39,10 @@ rootCommand.SetAction(_ =>
Console.WriteLine("Use --help to see available commands.");
});
// Deprecation notice for the pre-M8 `audit-log` command name. The command itself
// still works (it is an alias of `audit-config`), but using the old name emits a
// warning to stderr so scripts can be migrated.
AuditLogCommands.WriteDeprecationWarningIfNeeded(args, Console.Error);
var parseResult = CommandLineParser.Parse(rootCommand, args);
return await parseResult.InvokeAsync();