From 77949bdfffdfe31c480280293f370cd2e2203108 Mon Sep 17 00:00:00 2001 From: walon Date: Sat, 19 Jun 2021 17:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=20Excel2Te?= =?UTF-8?q?xtDiff=20=E6=96=B0=E5=A2=9E=20-f=20=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=8C=87=E5=AE=9A=E8=B0=83=E7=94=A8=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9diff=E7=A8=8B=E5=BA=8F=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Excel2TextDiff/Program.cs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Excel2TextDiff/Program.cs b/src/Excel2TextDiff/Program.cs index 4cd89f7..9a4a31f 100644 --- a/src/Excel2TextDiff/Program.cs +++ b/src/Excel2TextDiff/Program.cs @@ -2,6 +2,7 @@ using CommandLine.Text; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; namespace Excel2TextDiff @@ -17,21 +18,25 @@ namespace Excel2TextDiff [Option('p', SetName = "diff", Required = false, HelpText = "3rd diff program. default TortoiseMerge")] public string DiffProgram { get; set; } + [Option('f', SetName = "diff", Required = false, HelpText = "3rd diff program argument format. default is TortoiseMerge format:'/base:{0} /mine:{1}'")] + public string DiffProgramArgumentFormat { get; set; } + [Value(0)] public IList Files { get; set; } + + [Usage()] + public static IEnumerable Examples => new List + { + new Example("tranfrom to text", new CommandLineOptions { IsTransform = true, Files = new List{"a.xlsx", "a.txt" } }), + new Example("diff two excel file", new CommandLineOptions{ IsDiff = true, Files = new List{"a.xlsx", "b.xlsx"}}), + new Example("diff two excel file with TortoiseMerge", new CommandLineOptions{ IsDiff = true, DiffProgram = "TortoiseMerge",DiffProgramArgumentFormat = "/base:{0} /mine:{1}", Files = new List{"a.xlsx", "b.xlsx"}}), + }; } class Program { static void Main(string[] args) { - //if (args.Length != 2 && args.Length != 3) - //{ - // Console.WriteLine("Usage:"); - // Console.WriteLine("Excel2TextDiff [path_of_diff_program]"); - // return; - //} - var options = ParseOptions(args); System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); @@ -51,7 +56,7 @@ namespace Excel2TextDiff { if (options.Files.Count != 2) { - Console.WriteLine("Usage: Excel2TextDiff -d [-p ]"); + Console.WriteLine("Usage: Excel2TextDiff -d "); Environment.Exit(1); } @@ -63,10 +68,11 @@ namespace Excel2TextDiff var tempTxt2 = Path.GetTempFileName(); writer.TransformToTextAndSave(options.Files[1], tempTxt2); - string arg1 = $"/base:{tempTxt1.Replace('\\', '/')}"; - string arg2 = $"/mine:{tempTxt2.Replace('\\', '/')}"; - Console.WriteLine(" {0} {1}", arg1, arg2); - System.Diagnostics.Process.Start(diffProgame, new string[] { arg1, arg2 }); + ProcessStartInfo startInfo = new ProcessStartInfo(); + startInfo.FileName = diffProgame; + string argsFormation = options.DiffProgramArgumentFormat ?? "/base:{0} /mine:{1}"; + startInfo.Arguments = string.Format(argsFormation, tempTxt1, tempTxt2); + Process.Start(startInfo); } }