Generate/Check files from option files

This commit is contained in:
Fabrice Reix 2024-01-22 19:02:42 +01:00 committed by hurl-bot
parent ed0428be63
commit 5ed85d5b63
No known key found for this signature in database
GPG Key ID: 1283A2B4A0DCAF8D
4 changed files with 65 additions and 1 deletions

View File

@ -58,6 +58,10 @@ jobs:
if: always()
run: bin/check/rust_version.py 7
- name: Generated
if: always()
run: bin/check/generated.sh
- name: Coverage
if: always()
run: bin/check/coverage.sh

18
bin/check/generated.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
#!/bin/bash
set -Eeuo pipefail
cmds=(
bin/spec/options/generate_all.py
)
for cmd in "${cmds[@]}"; do
echo "$cmd"
"$cmd"
git diff --exit-code && exit_code=0 || exit_code=$?
if [ "$exit_code" -ne 0 ]; then
git --no-pager diff
echo -e "You must regenerate files by running '$cmd'"
echo "and commit them"
exit 1
fi
done

View File

@ -0,0 +1,43 @@
#!/usr/bin/env python3
from typing import List
import glob
from option import Option
import generate_source
def get_option_files(dir) -> List[str]:
return sorted(glob.glob(dir + "/*.option"))
def format_option_file(option_files: List[str]):
for option_file in option_files:
option = Option.parse_file(option_file)
open(option_file, "w").write(str(option) + "\n")
def generate_source_file(option_files: List[str], output_file: str):
options = sorted(
[Option.parse_file(option_file) for option_file in option_files],
key=lambda option: option.name,
)
src = generate_source.generate_source(options)
open(output_file, "w").write(src + "\n")
def main():
option_files_hurl = get_option_files("docs/spec/options/hurl")
option_files_hurlfmt = get_option_files("docs/spec/options/hurlfmt")
# Format option files
format_option_file(option_files_hurl)
format_option_file(option_files_hurlfmt)
# Generate Source files
generate_source_file(option_files_hurl, "packages/hurl/src/cli/options/commands.rs")
generate_source_file(
option_files_hurlfmt, "packages/hurlfmt/src/cli/options/commands.rs"
)
if __name__ == "__main__":
main()

View File

@ -6,4 +6,3 @@ conflict: no_color
Output full html file with css instead of html fragment (default).
This can be used only with html output.