【新增】 Excel2TextDiff 新增 -f 参数,用于指定调用第三方diff程序时的参数格式
parent
10c2768f1a
commit
77949bdfff
|
|
@ -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<string> Files { get; set; }
|
||||
|
||||
[Usage()]
|
||||
public static IEnumerable<Example> Examples => new List<Example>
|
||||
{
|
||||
new Example("tranfrom to text", new CommandLineOptions { IsTransform = true, Files = new List<string>{"a.xlsx", "a.txt" } }),
|
||||
new Example("diff two excel file", new CommandLineOptions{ IsDiff = true, Files = new List<string>{"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<string>{"a.xlsx", "b.xlsx"}}),
|
||||
};
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//if (args.Length != 2 && args.Length != 3)
|
||||
//{
|
||||
// Console.WriteLine("Usage:");
|
||||
// Console.WriteLine("Excel2TextDiff <file1> <file2> [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 <excel file 1> <excel file 2> [-p <diff programe>]");
|
||||
Console.WriteLine("Usage: Excel2TextDiff -d <excel file 1> <excel file 2> ");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue