command_line.py 1.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018 Collabora, Ltd.
#
# SPDX-License-Identifier: BSL-1.0
#
# Author(s):    Ryan Pavlik <ryan.pavlik@collabora.com>
#
# Purpose:      Generates a .cpp and .h file with the given stem,
#               containing the expected default/boilerplate contents

import argparse
from file_boilerplate import BoilerplateRun
from sys import exit

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('stem', metavar='stem', nargs='?',
                        help='Specify generated filename stem (.cpp and .h will be added)')
    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')
    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()
    if not args.noh:
        success = run.render(stem=args.stem,
                             ext="h").write(force=args.force) and success

    if not args.nocpp:
        success = run.render(ext='cpp',
                             stem=args.stem).write(force=args.force) and success
    if success:
        exit()
    exit(-1)