diff --git a/cfbs/build.py b/cfbs/build.py index fc55ae9..3c6ba6e 100644 --- a/cfbs/build.py +++ b/cfbs/build.py @@ -4,6 +4,7 @@ canonify, cp, find, + is_valid_arg_count, merge_json, mkdir, pad_right, @@ -222,14 +223,41 @@ def _perform_build_step(module, step, max_length): merged = merge_json(original, augment) if original else augment log.debug("Merged def.json: %s", pretty(merged)) write_json(path, merged) - else: - user_error("Unknown build step operation: %s" % operation) def perform_build_steps(config) -> int: if not config.get("build"): user_error("No 'build' key found in the configuration") - return 1 + + # mini-validation + for module in config.get("build", []): + for step in module["steps"]: + operation, args = split_command(step) + + if step.split() != [operation] + args: + user_error( + "Incorrect whitespace in the `%s` build step - singular spaces are required" + % step + ) + + if operation not in AVAILABLE_BUILD_STEPS: + user_error("Unknown build step operation: %s" % operation) + + expected = AVAILABLE_BUILD_STEPS[operation] + actual = len(args) + if not is_valid_arg_count(args, expected): + if type(expected) is int: + user_error( + "The `%s` build step expects %d arguments, %d were given" + % (step, expected, actual) + ) + else: + expected = int(expected[0:-1]) + user_error( + "The `%s` build step expects %d or more arguments, %d were given" + % (step, expected, actual) + ) + print("\nSteps:") module_name_length = config.longest_module_name() for module in config.get("build", []):