-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerate-guideline-templates.py
executable file
·100 lines (78 loc) · 2.46 KB
/
generate-guideline-templates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env -S uv run
# SPDX-License-Identifier: MIT OR Apache-2.0
# SPDX-FileCopyrightText: The Coding Guidelines Subcommittee Contributors
import argparse
import string
import random
# Configuration
CHARS = string.ascii_letters + string.digits
ID_LENGTH = 12
def generate_id(prefix):
"""Generate a random ID with the given prefix."""
random_part = "".join(random.choice(CHARS) for _ in range(ID_LENGTH))
return f"{prefix}_{random_part}"
def generate_guideline_template():
"""Generate a complete guideline template with all required sections."""
# Generate IDs for all sections
guideline_id = generate_id("gui")
rationale_id = generate_id("rat")
non_compliant_example_id = generate_id("non_compl_ex")
compliant_example_id = generate_id("compl_ex")
template = f""".. guideline:: Title Here
:id: {guideline_id}
:category:
:status: draft
:release:
:fls:
:decidability:
:scope:
:tags:
Description of the guideline goes here.
.. rationale::
:id: {rationale_id}
:status: draft
Explanation of why this guideline is important.
.. non_compliant_example::
:id: {non_compliant_example_id}
:status: draft
Explanation of code example.
.. code-block:: rust
fn example_function() {{
// Non-compliant implementation
}}
.. compliant_example::
:id: {compliant_example_id}
:status: draft
Explanation of code example.
.. code-block:: rust
fn example_function() {{
// Compliant implementation
}}
"""
return template
def parse_args():
"""Parse command-line arguments."""
parser = argparse.ArgumentParser(
description="Generate guideline templates with randomly generated IDs"
)
parser.add_argument(
"-n",
"--number-of-templates",
type=int,
default=1,
help="Number of templates to generate (default: 1)"
)
return parser.parse_args()
def main():
"""Generate the specified number of guideline templates."""
args = parse_args()
num_templates = args.number_of_templates
for i in range(num_templates):
if num_templates > 1:
print(f"=== Template {i+1} ===\n")
template = generate_guideline_template()
print(template)
if num_templates > 1 and i < num_templates - 1:
print("\n" + "=" * 80 + "\n")
if __name__ == "__main__":
main()