fix: resolve CI type annotation issues
This commit is contained in:
54
src/main.py
Normal file
54
src/main.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Optional
|
||||||
|
import argparse
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from requirements_to_gherkin.parser import RequirementsParser
|
||||||
|
from requirements_to_gherkin.generator import GherkinGenerator
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(config_path: Optional[Path] = None) -> dict:
|
||||||
|
if config_path is None or not config_path.exists():
|
||||||
|
return {"output_directory": "features"}
|
||||||
|
with open(config_path) as f:
|
||||||
|
return yaml.safe_load(f)
|
||||||
|
|
||||||
|
|
||||||
|
def main(args: Optional[List[str]] = None) -> None:
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Convert natural language requirements to Gherkin feature files"
|
||||||
|
)
|
||||||
|
parser.add_argument("input", type=Path, help="Input requirements file or directory")
|
||||||
|
parser.add_argument(
|
||||||
|
"-o", "--output", type=Path, default=Path("features"), help="Output directory"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-c", "--config", type=Path, help="Configuration file"
|
||||||
|
)
|
||||||
|
parsed_args = parser.parse_args(args)
|
||||||
|
|
||||||
|
config = load_config(parsed_args.config)
|
||||||
|
output_dir = parsed_args.output or Path(config.get("output_directory", "features"))
|
||||||
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
requirements_parser = RequirementsParser()
|
||||||
|
gherkin_generator = GherkinGenerator()
|
||||||
|
|
||||||
|
input_path = parsed_args.input
|
||||||
|
if input_path.is_file():
|
||||||
|
requirements = requirements_parser.parse_file(input_path)
|
||||||
|
features = gherkin_generator.generate(requirements)
|
||||||
|
for feature in features:
|
||||||
|
output_file = output_dir / f"{feature.name.lower().replace(' ', '_')}.feature"
|
||||||
|
output_file.write_text(feature.to_gherkin())
|
||||||
|
else:
|
||||||
|
for req_file in input_path.glob("*.txt"):
|
||||||
|
requirements = requirements_parser.parse_file(req_file)
|
||||||
|
features = gherkin_generator.generate(requirements)
|
||||||
|
for feature in features:
|
||||||
|
output_file = output_dir / f"{feature.name.lower().replace(' ', '_')}.feature"
|
||||||
|
output_file.write_text(feature.to_gherkin())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user