Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ftf generate-module [OPTIONS] /path/to/module
**Options**:
- `-i, --intent`: (prompt) The intent or purpose of the module.
- `-f, --flavor`: (prompt) The flavor or variant of the module.
- `-c, --cloud`: (prompt) Target cloud provider (e.g. aws, gcp, azure).
- `-c, --cloud`: (prompt) Target cloud provider(s). Supports single (e.g. aws) or comma-separated multiple clouds (e.g. aws,gcp,azure).
- `-t, --title`: (prompt) Human-readable title of the module.
- `-d, --description`: (prompt) Description outlining module functionality.

Expand Down
25 changes: 23 additions & 2 deletions ftf_cli/commands/generate_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,24 @@
help="The version of the module. If not provided, the default version will be 1.0. and the module will increment the version number.",
)
def generate_module(path, intent, flavor, cloud, title, description, version):
"""Generate a new module."""
"""
Generate a new module by rendering built-in templates into a target directory.

Parameters:
path (str): Destination base path where the module directory will be created.
intent (str): Intent name used to construct the module path and passed to templates.
flavor (str): Flavor name used to construct the module path and passed to templates.
cloud (str): Cloud identifier or comma-separated list of clouds (e.g., "aws" or "aws,azure").
title (str): Human-readable title passed into templates.
description (str): Description text passed into templates.
version (str): Version identifier appended to the module path; must not be a digits-only string.

Raises:
click.UsageError: If `version` is digits-only, if the requested version already exists, or if version parsing fails when attempting to suggest an alternate version.

Side effects:
Creates the module directory (including parent directories) and writes rendered template files into it.
"""
if str(version).isdigit():
raise click.UsageError(
f"❌ Version {version} is not a valid version. Use a valid version like 1.0"
Expand Down Expand Up @@ -57,6 +74,9 @@ def generate_module(path, intent, flavor, cloud, title, description, version):
templates_path = pkg_resources.files("ftf_cli.commands.templates")
env = Environment(loader=FileSystemLoader(str(templates_path)))

# Parse cloud input: supports both single ("aws") and multiple ("aws,azure,gcp")
cloud_list = [c.strip() for c in cloud.split(',')]

# Render and write templates
for template_name in [
"main.tf.j2",
Expand All @@ -69,6 +89,7 @@ def generate_module(path, intent, flavor, cloud, title, description, version):
intent=intent,
flavor=flavor,
cloud=cloud,
clouds=cloud_list,
title=title,
description=description,
)
Expand All @@ -77,4 +98,4 @@ def generate_module(path, intent, flavor, cloud, title, description, version):
) # Remove .j2 to get the real file name
with open(os.path.join(module_path, file_name), "w", encoding='utf-8') as f:
f.write(rendered_content)
click.echo(f"✅ Module generated at: {module_path}")
click.echo(f"✅ Module generated at: {module_path}")
2 changes: 1 addition & 1 deletion ftf_cli/commands/templates/facets.yaml.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
intent: {{ intent }}
flavor: {{ flavor }}
version: "1.0"
clouds: [ {{ cloud }} ]
clouds: {{ clouds }}
description: {{ description }}
spec:
title: {{ title }}
Expand Down