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
14 def print_and_exit(msg
):
15 sys
.stderr
.write(msg
+ "\n")
20 parser
= ArgumentParser(description
="Concatenate two files into a single file")
26 help="The output file. stdout is used if not given",
31 "files", metavar
="files", nargs
="+", help="The files to concatenate"
34 args
= parser
.parse_args()
36 if len(args
.files
) < 2:
37 print_and_exit("fewer than 2 inputs provided")
39 for filename
in args
.files
:
40 with
open(filename
, "r") as f
:
42 if len(data
) != 0 and data
[-1] != "\n":
44 assert len(data
) > 0 and "cannot cat empty files"
45 with
open(args
.output
, "w") as f
:
49 if __name__
== "__main__":