2 #===----------------------------------------------------------------------===##
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 #===----------------------------------------------------------------------===##
10 from argparse
import ArgumentParser
13 def print_and_exit(msg
):
14 sys
.stderr
.write(msg
+ '\n')
18 parser
= ArgumentParser(
19 description
="Concatenate two files into a single file")
21 '-o', '--output', dest
='output', required
=True,
22 help='The output file. stdout is used if not given',
23 type=str, action
='store')
25 'files', metavar
='files', nargs
='+',
26 help='The files to concatenate')
28 args
= parser
.parse_args()
30 if len(args
.files
) < 2:
31 print_and_exit('fewer than 2 inputs provided')
33 for filename
in args
.files
:
34 with
open(filename
, 'r') as f
:
36 if len(data
) != 0 and data
[-1] != '\n':
38 assert len(data
) > 0 and "cannot cat empty files"
39 with
open(args
.output
, 'w') as f
:
43 if __name__
== '__main__':