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); } }