[mapguide-commits] r10151 - in branches/4.0/MgDev/Server/RepositoryAdmin/app: . Commands
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Jun 12 07:54:41 PDT 2025
Author: jng
Date: 2025-06-12 07:54:40 -0700 (Thu, 12 Jun 2025)
New Revision: 10151
Added:
branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/RootCommand.cs
branches/4.0/MgDev/Server/RepositoryAdmin/app/nuget.config
Modified:
branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/App.cs
branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/BackupCommand.cs
branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/BaseCommand.cs
branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/CommandException.cs
branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/RestoreCommand.cs
branches/4.0/MgDev/Server/RepositoryAdmin/app/MapGuide.RepositoryAdmin.csproj
branches/4.0/MgDev/Server/RepositoryAdmin/app/Program.cs
branches/4.0/MgDev/Server/RepositoryAdmin/app/Strings.Designer.cs
branches/4.0/MgDev/Server/RepositoryAdmin/app/Strings.resx
Log:
#2879: Migrate from CommandLine to DotMake.CommandLine as that supports trimming, which is a hard requirement as we intend to publish a trimmed, single-file, self-contained binary
Modified: branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/App.cs
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/App.cs 2025-06-12 12:58:58 UTC (rev 10150)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/App.cs 2025-06-12 14:54:40 UTC (rev 10151)
@@ -7,7 +7,6 @@
TextWriter stdout,
TextWriter stderr,
FileInfo dbArchive,
- FileInfo dbCheckpoint,
FileInfo dbRecover)
{
public void Stdout(string msg) => stdout.WriteLine(msg);
@@ -130,7 +129,7 @@
logFiles = this.GetLogFiles(cmd.InputPath.FullName, false).ToList();
numUnusedFiles = unusedFiles.Count;
- if (bk.IncrementalLevel != BackupCommand.MIN_INCREMENTAL_LEVEL && numUnusedFiles > 0)
+ if (bk.Level != BackupCommand.MIN_INCREMENTAL_LEVEL && numUnusedFiles > 0)
{
this.TransferFiles(outDir, unusedFiles, 0, true);
}
Modified: branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/BackupCommand.cs
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/BackupCommand.cs 2025-06-12 12:58:58 UTC (rev 10150)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/BackupCommand.cs 2025-06-12 14:54:40 UTC (rev 10151)
@@ -1,17 +1,22 @@
-using CommandLine;
+using DotMake.CommandLine;
namespace MapGuide.RepositoryAdmin.Commands;
-[Verb("backup", HelpText = "VerbHelp_Backup", ResourceType = typeof(Strings))]
+[CliCommand(Name = "backup", Description = nameof(Strings.VerbHelp_Backup))]
public class BackupCommand : BaseCommand
{
- [Option('l', "incremental-level", Required = true)]
- public required int IncrementalLevel { get; set; }
+ // HACK: Source generator won't generate if attribute placed on base property, so that has been made
+ // abstract and we're decorating here
+ [CliOption(Required = false, Description = nameof(Strings.ArgHelp_Common_BinPath))]
+ public override DirectoryInfo? BinPath { get; set; }
- [Option('i', "input-path", Required = true, HelpText = "ArgHelp_Backup_InputPath", ResourceType = typeof(Strings))]
+ [CliOption(Description = nameof(Strings.ArgHelp_Backup_Level))]
+ public required int Level { get; set; }
+
+ [CliOption(Description = nameof(Strings.ArgHelp_Backup_InputPath))]
public override required DirectoryInfo InputPath { get; set; }
- [Option('o', "output-path", Required = true, HelpText = "ArgHelp_Backup_OutputPath", ResourceType = typeof(Strings))]
+ [CliOption(Description = nameof(Strings.ArgHelp_Backup_OutputPath))]
public override required DirectoryInfo OutputPath { get; set; }
public const int MIN_INCREMENTAL_LEVEL = 0;
@@ -28,9 +33,9 @@
{
OutputPath.Create();
}
- if (IncrementalLevel < MIN_INCREMENTAL_LEVEL || IncrementalLevel > MAX_INCREMENTAL_LEVEL)
+ if (Level < MIN_INCREMENTAL_LEVEL || Level > MAX_INCREMENTAL_LEVEL)
{
- app.Stderr(string.Format(Strings.IDS_ERR_ARGUMENT_OUT_OF_RANGE, IncrementalLevel));
+ app.Stderr(string.Format(Strings.IDS_ERR_ARGUMENT_OUT_OF_RANGE, Level));
return 1;
}
@@ -38,7 +43,7 @@
//tools.Stdout($"Input path: {InputPath}");
//tools.Stdout($"Output path: {OutputPath}");
- if (IncrementalLevel == 0)
+ if (Level == 0)
{
return app.BackupOfflineRepositories();
}
Modified: branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/BaseCommand.cs
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/BaseCommand.cs 2025-06-12 12:58:58 UTC (rev 10150)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/BaseCommand.cs 2025-06-12 14:54:40 UTC (rev 10151)
@@ -1,16 +1,15 @@
-using CommandLine;
-
namespace MapGuide.RepositoryAdmin.Commands;
public abstract class BaseCommand : ICommonCommand
{
- [Option('b', "bin-path", Required = false, HelpText = "ArgHelp_Common_BinPath", ResourceType = typeof(Strings))]
- public DirectoryInfo? BinPath { get; set; }
+ public abstract DirectoryInfo? BinPath { get; set; }
public abstract required DirectoryInfo InputPath { get; set; }
public abstract required DirectoryInfo OutputPath { get; set; }
+ public int Run() => Execute(Console.Out, Console.Error);
+
public int Execute(TextWriter stdout, TextWriter stderr)
{
var dir = BinPath ?? new DirectoryInfo("../bin");
@@ -21,7 +20,6 @@
}
FileInfo? dbArchive = null;
- FileInfo? dbCheckpoint = null;
FileInfo? dbRecover = null;
foreach (var f in dir.EnumerateFiles())
@@ -31,9 +29,6 @@
case string s when s.StartsWith("db_archive"):
dbArchive = f;
break;
- case string s when s.StartsWith("db_checkpoint"):
- dbCheckpoint = f;
- break;
case string s when s.StartsWith("db_recover"):
dbRecover = f;
break;
@@ -47,11 +42,6 @@
stderr.WriteLine(string.Format(Strings.IDS_ERR_FILE_NOT_FOUND, "db_archive"));
return 1;
}
- if (dbCheckpoint == null || !dbCheckpoint.Exists)
- {
- stderr.WriteLine(string.Format(Strings.IDS_ERR_FILE_NOT_FOUND, "db_checkpoint"));
- return 1;
- }
if (dbRecover == null || !dbRecover.Exists)
{
stderr.WriteLine(string.Format(Strings.IDS_ERR_FILE_NOT_FOUND, "db_recover"));
@@ -60,7 +50,7 @@
try
{
- var app = new App(this, stdout, stderr, dbArchive, dbCheckpoint, dbRecover);
+ var app = new App(this, stdout, stderr, dbArchive, dbRecover);
var res = ExecuteCore(app);
stdout.WriteLine(Strings.IDS_PROGRESS_OPERATION_SUCCEEDED);
return res;
Modified: branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/CommandException.cs
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/CommandException.cs 2025-06-12 12:58:58 UTC (rev 10150)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/CommandException.cs 2025-06-12 14:54:40 UTC (rev 10151)
@@ -7,7 +7,4 @@
public CommandException() { }
public CommandException(string message) : base(message) { }
public CommandException(string message, Exception inner) : base(message, inner) { }
- protected CommandException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
Modified: branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/RestoreCommand.cs
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/RestoreCommand.cs 2025-06-12 12:58:58 UTC (rev 10150)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/RestoreCommand.cs 2025-06-12 14:54:40 UTC (rev 10151)
@@ -1,14 +1,19 @@
-using CommandLine;
+using DotMake.CommandLine;
namespace MapGuide.RepositoryAdmin.Commands;
-[Verb("restore", HelpText = "VerbHelp_Restore", ResourceType = typeof(Strings))]
+[CliCommand(Name = "restore", Description = nameof(Strings.VerbHelp_Restore))]
public class RestoreCommand : BaseCommand, ICommonCommand
{
- [Option('i', "input-path", Required = true, HelpText = "ArgHelp_Restore_InputPath", ResourceType = typeof(Strings))]
+ // HACK: Source generator won't generate if attribute placed on base property, so that has been made
+ // abstract and we're decorating here
+ [CliOption(Required = false, Description = nameof(Strings.ArgHelp_Common_BinPath))]
+ public override DirectoryInfo? BinPath { get; set; }
+
+ [CliOption(Description = nameof(Strings.ArgHelp_Restore_InputPath))]
public override required DirectoryInfo InputPath { get; set; }
- [Option('o', "output-path", Required = true, HelpText = "ArgHelp_Restore_OutputPath", ResourceType = typeof(Strings))]
+ [CliOption(Description = nameof(Strings.ArgHelp_Restore_OutputPath))]
public override required DirectoryInfo OutputPath { get; set; }
protected override int ExecuteCore(App app)
Added: branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/RootCommand.cs
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/RootCommand.cs (rev 0)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/Commands/RootCommand.cs 2025-06-12 14:54:40 UTC (rev 10151)
@@ -0,0 +1,8 @@
+using DotMake.CommandLine;
+
+namespace MapGuide.RepositoryAdmin.Commands;
+
+[CliCommand(Children = [ typeof(BackupCommand), typeof(RestoreCommand) ])]
+public class RootCommand
+{
+}
Modified: branches/4.0/MgDev/Server/RepositoryAdmin/app/MapGuide.RepositoryAdmin.csproj
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/MapGuide.RepositoryAdmin.csproj 2025-06-12 12:58:58 UTC (rev 10150)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/MapGuide.RepositoryAdmin.csproj 2025-06-12 14:54:40 UTC (rev 10151)
@@ -5,10 +5,24 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
+ <EnableTrimAnalyzer>true</EnableTrimAnalyzer>
+ <PublishSingleFile>true</PublishSingleFile>
+ <PublishTrimmed>true</PublishTrimmed>
+ <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
+ <SelfContained>true</SelfContained>
+ <!-- Disabled features to maximize trimming -->
+ <HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
+ <XmlResolverIsNetworkingEnabledByDefault >false</XmlResolverIsNetworkingEnabledByDefault>
+ <EventSourceSupport>false</EventSourceSupport>
+ <EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
+ <EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>
+ <MetricsSupport>false</MetricsSupport>
+ <MetadataUpdaterSupport>false</MetadataUpdaterSupport>
+ <TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="CommandLineParser" Version="2.9.1" />
+ <PackageReference Include="DotMake.CommandLine" Version="2.4.2" />
</ItemGroup>
<ItemGroup>
Modified: branches/4.0/MgDev/Server/RepositoryAdmin/app/Program.cs
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/Program.cs 2025-06-12 12:58:58 UTC (rev 10150)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/Program.cs 2025-06-12 14:54:40 UTC (rev 10151)
@@ -1,19 +1,5 @@
-using CommandLine;
+
+using DotMake.CommandLine;
using MapGuide.RepositoryAdmin.Commands;
-using System.Reflection;
-var commandTypes = Assembly.GetExecutingAssembly()
- .GetTypes()
- .Where(t => typeof(BaseCommand).IsAssignableFrom(t) && t.GetCustomAttribute<VerbAttribute>() != null && !t.IsAbstract)
- .ToArray();
-
-Parser.Default
- .ParseArguments(args, commandTypes)
- .WithParsed(opts =>
- {
- Environment.ExitCode = ((BaseCommand)opts).Execute(Console.Out, Console.Error);
- })
- .WithNotParsed(err =>
- {
- Environment.ExitCode = 1;
- });
\ No newline at end of file
+return Cli.Run<RootCommand>(args);
\ No newline at end of file
Modified: branches/4.0/MgDev/Server/RepositoryAdmin/app/Strings.Designer.cs
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/Strings.Designer.cs 2025-06-12 12:58:58 UTC (rev 10150)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/Strings.Designer.cs 2025-06-12 14:54:40 UTC (rev 10151)
@@ -70,6 +70,20 @@
}
/// <summary>
+ /// Looks up a localized string similar to Incremental level (from 0 to 10).
+ ///= 0, Offline (cold) backup (A full snapshot is always taken)
+ ///> 0, Online (hot) backup. For example, for an incremental level value of 2:
+ /// - If the number of active log files in the previous snapshot is less than or equal to 2, an incremental snapshot is taken.
+ /// - If the number of active log files in the previous snapshot is greater than 2, a full snapshot is taken.
+ ///Note that active log files are files containing data that has NOT been saved to the database (by de [rest of string was truncated]";.
+ /// </summary>
+ public static string ArgHelp_Backup_Level {
+ get {
+ return ResourceManager.GetString("ArgHelp_Backup_Level", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Path to the destination location to where the repository is backed up. For offline (cold) backups, repositories are archived to a time-stamped sub-directory. For online (hot) backups, repositories are acrhived to the 'CurrentHotBackup' or a time-stamped sub-directory when taking an incremental or full snapshot respectively.
/// </summary>
public static string ArgHelp_Backup_OutputPath {
Modified: branches/4.0/MgDev/Server/RepositoryAdmin/app/Strings.resx
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/Strings.resx 2025-06-12 12:58:58 UTC (rev 10150)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/Strings.resx 2025-06-12 14:54:40 UTC (rev 10151)
@@ -120,6 +120,14 @@
<data name="ArgHelp_Backup_InputPath" xml:space="preserve">
<value>Path to the source location from where the repository is backed up</value>
</data>
+ <data name="ArgHelp_Backup_Level" xml:space="preserve">
+ <value>Incremental level (from 0 to 10).
+= 0, Offline (cold) backup (A full snapshot is always taken)
+> 0, Online (hot) backup. For example, for an incremental level value of 2:
+ - If the number of active log files in the previous snapshot is less than or equal to 2, an incremental snapshot is taken.
+ - If the number of active log files in the previous snapshot is greater than 2, a full snapshot is taken.
+Note that active log files are files containing data that has NOT been saved to the database (by default, the size of a log file is about 10MB)</value>
+ </data>
<data name="ArgHelp_Backup_OutputPath" xml:space="preserve">
<value>Path to the destination location to where the repository is backed up. For offline (cold) backups, repositories are archived to a time-stamped sub-directory. For online (hot) backups, repositories are acrhived to the 'CurrentHotBackup' or a time-stamped sub-directory when taking an incremental or full snapshot respectively</value>
</data>
Added: branches/4.0/MgDev/Server/RepositoryAdmin/app/nuget.config
===================================================================
--- branches/4.0/MgDev/Server/RepositoryAdmin/app/nuget.config (rev 0)
+++ branches/4.0/MgDev/Server/RepositoryAdmin/app/nuget.config 2025-06-12 14:54:40 UTC (rev 10151)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <packageSources>
+ <clear />
+ <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
+ </packageSources>
+</configuration>
\ No newline at end of file
More information about the mapguide-commits
mailing list