65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
import yaml
|
|
|
|
from argparse import ArgumentParser
|
|
from argparse import Namespace
|
|
from pathlib import Path
|
|
from semver import Version
|
|
|
|
|
|
# Load application configurations.
|
|
cfgdir = Path.home() / ".config" / "chinook" / "remotes.yaml"
|
|
remotes = yaml.full_load(cfgdir) if Path.exists(cfgdir) else []
|
|
|
|
|
|
def _build(args: Namespace) -> None:
|
|
from chinook import management
|
|
from chinook import pipeline
|
|
|
|
from chinook._logger import logger
|
|
from chinook.models import Destination
|
|
from chinook.models import Origination
|
|
|
|
try:
|
|
projpath = Path(args.project)
|
|
projcfg = management.load(projpath)
|
|
if projcfg != None:
|
|
root = projpath.parent
|
|
projcfg.origination = Origination(root)
|
|
projcfg.destination = Destination(root)
|
|
return pipeline.build(projcfg)
|
|
except Exception as err:
|
|
logger.exception(str(err))
|
|
logger.critical("Failed to build project")
|
|
|
|
|
|
def main() -> None:
|
|
# Parent parser to all subcommands.
|
|
parser = ArgumentParser(
|
|
prog = "chinook",
|
|
description = "Opinionated build tool for C/C++!"
|
|
)
|
|
|
|
commands = parser.add_subparsers(required=True)
|
|
buildcmd = commands.add_parser("build",help="Builds your Chinook project")
|
|
buildcmd.set_defaults(func=_build)
|
|
buildcmd.add_argument(
|
|
"project",
|
|
nargs="?",
|
|
default=".",
|
|
type=str,
|
|
help="The path to the project to build",
|
|
metavar="PROJECT"
|
|
)
|
|
|
|
print("\n".join([
|
|
"┏┓┓ • ┓ ",
|
|
"┃ ┣┓┓┏┓┏┓┏┓┃┏",
|
|
"┗┛┛┗┗┛┗┗┛┗┛┛┗ v" + str(Version(major=0,minor=1,patch=0))
|
|
]))
|
|
arguments = parser.parse_args()
|
|
arguments.func(arguments)
|
|
|
|
|
|
# Auto execute.
|
|
if __name__ == "__main__": main()
|