From 788e8f237be49096e7af55fc1b19d52335ea2054 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Mon, 26 Aug 2024 10:43:49 +0000 Subject: [PATCH] feat(cli): support replace cdn domain of html output Signed-off-by: catcherwong --- src/RDBCli/Commands/CommonCLIOptions.cs | 11 +++++++++++ src/RDBCli/Commands/MemoryCommand.cs | 10 ++++++++-- src/RDBCli/Helpers/CommonHelper.Const.cs | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/RDBCli/Commands/CommonCLIOptions.cs b/src/RDBCli/Commands/CommonCLIOptions.cs index 22e7a04..aec5061 100644 --- a/src/RDBCli/Commands/CommonCLIOptions.cs +++ b/src/RDBCli/Commands/CommonCLIOptions.cs @@ -172,5 +172,16 @@ public static Option SepPrefixCountOption() return option; } + + public static Option CDNOption() + { + Option option = + new Option( + aliases: new string[] { "--cdn" }, + getDefaultValue: () => "unpkg.com", + description: "The cdn domain for html output"); + + return option; + } } } diff --git a/src/RDBCli/Commands/MemoryCommand.cs b/src/RDBCli/Commands/MemoryCommand.cs index 170d273..734432f 100644 --- a/src/RDBCli/Commands/MemoryCommand.cs +++ b/src/RDBCli/Commands/MemoryCommand.cs @@ -24,6 +24,7 @@ internal class MemoryCommand : Command private static Option _isPermanentOption = CommonCLIOptions.IsPermanentOption(); private static Option _isIgnoreFieldOfLargestElemOption = CommonCLIOptions.IsIgnoreFieldOfLargestElemOption(); private static Option _keySuffixEnableOption = CommonCLIOptions.KeySuffixEnableOption(); + private static Option _cdnOption = CommonCLIOptions.CDNOption(); private static Argument _fileArg = CommonCLIArguments.FileArgument(); public MemoryCommand() @@ -41,6 +42,7 @@ public MemoryCommand() this.AddOption(_isPermanentOption); this.AddOption(_isIgnoreFieldOfLargestElemOption); this.AddOption(_keySuffixEnableOption); + this.AddOption(_cdnOption); this.AddArgument(_fileArg); this.SetHandler((InvocationContext context) => @@ -98,14 +100,14 @@ private void Do(InvocationContext context, CommandOptions options) dict.permCount = (int)(perm?.Num ?? 0); dict.permMem = (long)(perm?.Bytes ?? 0); - var path = WriteFile(dict, options.Output, options.OutputType); + var path = WriteFile(dict, options.Output, options.OutputType, options.CDN); sw.Stop(); console.WriteLine($"total cost: {sw.ElapsedMilliseconds}ms"); console.WriteLine($"result path: {path}\n"); } - private string WriteFile(MemoryAnslysisResult dict, string output, string type) + private string WriteFile(MemoryAnslysisResult dict, string output, string type, string cdn) { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"res.{type}"); @@ -137,6 +139,7 @@ private string WriteFile(MemoryAnslysisResult dict, string output, string type) { var str = JsonSerializer.Serialize(dict, typeof(MemoryAnslysisResult), context); var tpl = CommonHelper.TplHtmlString; + tpl = tpl.Replace("{{CDNDOMAIN}}", cdn); tpl = tpl.Replace("{{CLIDATA}}", str); bytes = System.Text.Encoding.UTF8.GetBytes(tpl); @@ -182,6 +185,7 @@ private class CommandOptions public int SepPrefixCount { get; set; } public bool? IsIgnoreFole { get; set; } public bool? keySuffixEnable { get; set; } + public string CDN { get; set; } public static CommandOptions FromContext(InvocationContext context) @@ -199,6 +203,7 @@ public static CommandOptions FromContext(InvocationContext context) var isPermanent = context.ParseResult.GetValueForOption(_isPermanentOption); var isIgnoreFole = context.ParseResult.GetValueForOption(_isIgnoreFieldOfLargestElemOption); var keySuffixEnable = context.ParseResult.GetValueForOption(_keySuffixEnableOption); + var cdn = context.ParseResult.GetValueForOption(_cdnOption); var parseFilter = new RDBParser.ParserFilter() { @@ -220,6 +225,7 @@ public static CommandOptions FromContext(InvocationContext context) SepPrefixCount = sepPrefixCount, IsIgnoreFole = isIgnoreFole, keySuffixEnable = keySuffixEnable, + CDN = cdn, }; } } diff --git a/src/RDBCli/Helpers/CommonHelper.Const.cs b/src/RDBCli/Helpers/CommonHelper.Const.cs index 3fd38f0..00fd515 100644 --- a/src/RDBCli/Helpers/CommonHelper.Const.cs +++ b/src/RDBCli/Helpers/CommonHelper.Const.cs @@ -5,7 +5,7 @@ namespace RDBCli internal static partial class CommonHelper { // compress Tpl/tpl.html to get this value. - internal const string TplHtmlString = "rdb-cli,offline key analysis

Basic Information


RDB Version:
Redis Version:

Total Memory Usage of Keys

Total Number of Keys


Expired Keys

Memory Usage by Expired Keys

Permanent Keys

Memory Usage by Permanent Keys


Details Information








" + + internal const string TplHtmlString = "rdb-cli,offline key analysis

Basic Information


RDB Version:
Redis Version:

Total Memory Usage of Keys

Total Number of Keys


Expired Keys

Memory Usage by Expired Keys

Permanent Keys

Memory Usage by Permanent Keys


Details Information








" + "" + "";