# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617"""Concatenate multiple CDDL files into a single output file.1819Usage:20merge_cddl.py <output> <input1> [<input2> ...]21"""2223import sys242526def main() -> None:27if len(sys.argv) < 3:28usage = (__doc__ or "Usage:\n merge_cddl.py <output> <input1> [<input2> ...]\n").strip()29print(usage, file=sys.stderr)30raise SystemExit(1)3132out_path = sys.argv[1]33input_paths = sys.argv[2:]34with open(out_path, "wb") as out_f:35for index, input_path in enumerate(input_paths):36if index > 0:37# Ensure files that lack a trailing newline don't accidentally38# join their last and first tokens across the boundary.39out_f.write(b"\n")40with open(input_path, "rb") as in_f:41out_f.write(in_f.read())424344if __name__ == "__main__":45main()464748