command_line.py 1.63 KB
Newer Older
1 2 3
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
4
# Copyright (c) 2018-2019 Collabora, Ltd.
5 6 7 8 9
#
# SPDX-License-Identifier: BSL-1.0
#
# Author(s):    Ryan Pavlik <ryan.pavlik@collabora.com>
#
10
# Purpose:      Generates code files (by default .cpp and .h) with the given stem,
11 12 13 14 15 16
#               containing the expected default/boilerplate contents

import argparse
from file_boilerplate import BoilerplateRun
from sys import exit

17

18 19 20
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('stem', metavar='stem', nargs='?',
21
                        help='Specify generated filename stem (file extensions.cpp and .h will be added)')
22 23 24 25
    parser.add_argument('--noh', action='store_true', default=False,
                        help='Skip generating the .h file')
    parser.add_argument('--nocpp', action='store_true', default=False,
                        help='Skip generating the .cpp file')
26 27
    parser.add_argument('-t', '--type', action='append', default=[],
                        help='Specify file types (nominally, extensions) to explicitly use.')
28 29 30 31 32 33
    parser.add_argument('-f', '--force', action='store_true', default=False,
                        help='Write file(s) even if already existing')
    args = parser.parse_args()

    success = True
    run = BoilerplateRun()
34 35 36 37 38 39 40 41
    file_types = args.type
    if not file_types:
        if not args.noh:
            file_types.append('h')
        if not args.nocpp:
            file_types.append('cpp')

    for file_type in file_types:
42
        success = run.render(stem=args.stem,
43
                             ext=file_type).write(force=args.force) and success
44 45 46 47

    if success:
        exit()
    exit(-1)