mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-10-26 08:18:26 +03:00
Generate/Check files from option files
This commit is contained in:
parent
ed0428be63
commit
5ed85d5b63
4
.github/workflows/check.yml
vendored
4
.github/workflows/check.yml
vendored
@ -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
18
bin/check/generated.sh
Executable 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
|
43
bin/spec/options/generate_all.py
Executable file
43
bin/spec/options/generate_all.py
Executable 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()
|
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user