@@ -224,6 +224,7 @@ var (
224224 flag_max_goroutines = 1
225225 flag_p_keys string
226226 flag_html_output string = "diff.html"
227+ flag_txt_output string = "diff.txt"
227228 flag_csv_delta string = "delta.csv"
228229)
229230
@@ -244,8 +245,10 @@ var regexp_exclude_files *regexp.Regexp
244245
245246// Buffered stdout
246247var (
247- out * bufio.Writer
248- out_lock sync.Mutex
248+ out * bufio.Writer
249+ out_lock sync.Mutex
250+ outputFile * os.File
251+ errF error
249252)
250253
251254// html entity strings
@@ -306,7 +309,8 @@ func main() {
306309 flag .BoolVar (& flag_suppress_line_changes , "l" , flag_suppress_line_changes , "Do not display changes within lines" )
307310 flag .BoolVar (& flag_suppress_missing_file , "m" , flag_suppress_missing_file , "Do not show content if corresponding file is missing" )
308311 flag .BoolVar (& flag_unified_context , "u" , flag_unified_context , "Unified context" )
309- flag .BoolVar (& flag_output_as_text , "n" , flag_output_as_text , "Output using 'diff' text format instead of HTML" )
312+ flag .BoolVar (& flag_output_as_text , "txt" , flag_output_as_text , "Output using 'diff' text format instead of HTML" )
313+ flag .StringVar (& flag_txt_output , "n" , flag_txt_output , "Generate given txt diff file" )
310314
311315 flag .StringVar (& flag_p_keys , "key" , "" , "The Primary Key Columns" )
312316 flag .StringVar (& flag_html_output , "html" , flag_html_output , "Generate HTML diff file" )
@@ -316,12 +320,20 @@ func main() {
316320
317321 flag .Parse ()
318322
319- output_html_file , err := os .Create (flag_html_output )
320- if err != nil {
321- usage (err .Error ())
323+ if flag_txt_output != "diff.txt" {
324+ flag_output_as_text = true
325+ }
326+
327+ if flag_output_as_text {
328+ outputFile , errF = os .Create (flag_txt_output )
329+ } else {
330+ outputFile , errF = os .Create (flag_html_output )
322331 }
323332
324- out = bufio .NewWriterSize (output_html_file , OUTPUT_BUF_SIZE )
333+ if errF != nil {
334+ usage (errF .Error ())
335+ }
336+ out = bufio .NewWriterSize (outputFile , OUTPUT_BUF_SIZE )
325337
326338 if flag_version {
327339 version ()
@@ -349,7 +361,7 @@ func main() {
349361 // flush output on termination
350362 defer func () {
351363 out .Flush ()
352- output_html_file .Close ()
364+ outputFile .Close ()
353365 }()
354366
355367 // choose which compare and hash function to use
@@ -1250,9 +1262,7 @@ func sortCsv(fname string) (string, os.FileInfo) {
12501262 file , err := os .Open (fname )
12511263 defer file .Close ()
12521264
1253- if strings .HasSuffix (fname , ".colreordered" ) {
1254- defer os .Remove (fname )
1255- }
1265+ defer removeFile (fname , ".colreordered" )
12561266
12571267 fnameSorted := fname + ".sorted"
12581268 wfile , err := os .Create (fnameSorted )
@@ -1363,9 +1373,7 @@ func open_file(fname string, finfo os.FileInfo) *Filedata {
13631373// Close file (and umap it)
13641374func (file * Filedata ) close_file () {
13651375
1366- if strings .HasSuffix (file .name , ".sorted" ) {
1367- defer os .Remove (file .name )
1368- }
1376+ defer removeFile (file .name , ".sorted" )
13691377
13701378 if file .osfile != nil {
13711379 if file .is_mapped && file .data != nil {
@@ -1377,6 +1385,12 @@ func (file *Filedata) close_file() {
13771385 file .data = nil
13781386}
13791387
1388+ func removeFile (fileName string , ext string ) {
1389+ if strings .HasSuffix (fileName , ext ) {
1390+ os .Remove (fileName )
1391+ }
1392+ }
1393+
13801394// check if file is binary
13811395func (file * Filedata ) check_binary () {
13821396 if file .data == nil {
0 commit comments