netherframe.cli 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. netherframe/cli/__init__.py +1 -0
  2. netherframe/cli/__main__.py +4 -0
  3. netherframe/cli/commands/__init__.py +93 -0
  4. netherframe/cli/commands/backend.py +305 -0
  5. netherframe/cli/commands/config_command.py +98 -0
  6. netherframe/cli/commands/convert.py +40 -0
  7. netherframe/cli/commands/discover.py +679 -0
  8. netherframe/cli/commands/drift.py +499 -0
  9. netherframe/cli/commands/encode.py +130 -0
  10. netherframe/cli/commands/generation.py +861 -0
  11. netherframe/cli/commands/graph_state.py +439 -0
  12. netherframe/cli/commands/hybrid.py +461 -0
  13. netherframe/cli/commands/idiff.py +493 -0
  14. netherframe/cli/commands/infrastructure.py +1182 -0
  15. netherframe/cli/commands/init_command.py +11 -0
  16. netherframe/cli/commands/lint.py +49 -0
  17. netherframe/cli/commands/providers.py +315 -0
  18. netherframe/cli/commands/shell_command.py +17 -0
  19. netherframe/cli/commands/skill.py +167 -0
  20. netherframe/cli/commands/synthesis.py +732 -0
  21. netherframe/cli/commands/terraform_command.py +17 -0
  22. netherframe/cli/commands/watch_command.py +117 -0
  23. netherframe/cli/entrypoint.py +18 -0
  24. netherframe/cli/logging.py +33 -0
  25. netherframe/cli/main.py +177 -0
  26. netherframe/cli/options.py +32 -0
  27. netherframe/cli/py.typed +0 -0
  28. netherframe/cli/services/__init__.py +1 -0
  29. netherframe/cli/services/app_loader.py +62 -0
  30. netherframe/cli/services/app_resolver.py +205 -0
  31. netherframe/cli/services/graph_onboarding.py +144 -0
  32. netherframe/cli/services/legacy_cli.py +51 -0
  33. netherframe/cli/services/project_config.py +107 -0
  34. netherframe/cli/services/provider_batch.py +620 -0
  35. netherframe/cli/services/stack_inventory.py +342 -0
  36. netherframe/cli/skills/netherframe/SKILL.md +53 -0
  37. netherframe/cli/skills/netherframe/agents/openai.yaml +3 -0
  38. netherframe/cli/skills/netherframe/references/authoring.md +77 -0
  39. netherframe/cli/skills/netherframe/references/execution.md +70 -0
  40. netherframe/cli/skills/netherframe/references/migration.md +69 -0
  41. netherframe/cli/state_migration.py +111 -0
  42. netherframe/cli/tui/__init__.py +1 -0
  43. netherframe/cli/tui/plan_filters.py +200 -0
  44. netherframe/cli/tui/plan_models.py +51 -0
  45. netherframe/cli/tui/plan_viewer.py +745 -0
  46. netherframe/cli/ui.py +25 -0
  47. netherframe_cli-0.2.1.dist-info/METADATA +86 -0
  48. netherframe_cli-0.2.1.dist-info/RECORD +92 -0
  49. netherframe_cli-0.2.1.dist-info/WHEEL +4 -0
  50. netherframe_cli-0.2.1.dist-info/entry_points.txt +3 -0
  51. netherframe_cli-0.2.1.dist-info/licenses/LICENSE +21 -0
  52. nf/cli/__init__.py +4 -0
  53. nf/cli/__main__.py +4 -0
  54. nf/cli/commands/__init__.py +4 -0
  55. nf/cli/commands/backend.py +4 -0
  56. nf/cli/commands/config_command.py +4 -0
  57. nf/cli/commands/convert.py +4 -0
  58. nf/cli/commands/discover.py +4 -0
  59. nf/cli/commands/drift.py +4 -0
  60. nf/cli/commands/encode.py +4 -0
  61. nf/cli/commands/generation.py +4 -0
  62. nf/cli/commands/graph_state.py +4 -0
  63. nf/cli/commands/hybrid.py +4 -0
  64. nf/cli/commands/idiff.py +4 -0
  65. nf/cli/commands/infrastructure.py +4 -0
  66. nf/cli/commands/init_command.py +4 -0
  67. nf/cli/commands/lint.py +4 -0
  68. nf/cli/commands/providers.py +4 -0
  69. nf/cli/commands/shell_command.py +4 -0
  70. nf/cli/commands/skill.py +4 -0
  71. nf/cli/commands/synthesis.py +4 -0
  72. nf/cli/commands/terraform_command.py +4 -0
  73. nf/cli/commands/watch_command.py +4 -0
  74. nf/cli/entrypoint.py +4 -0
  75. nf/cli/logging.py +4 -0
  76. nf/cli/main.py +4 -0
  77. nf/cli/options.py +4 -0
  78. nf/cli/py.typed +0 -0
  79. nf/cli/services/__init__.py +4 -0
  80. nf/cli/services/app_loader.py +4 -0
  81. nf/cli/services/app_resolver.py +4 -0
  82. nf/cli/services/graph_onboarding.py +4 -0
  83. nf/cli/services/legacy_cli.py +4 -0
  84. nf/cli/services/project_config.py +4 -0
  85. nf/cli/services/provider_batch.py +4 -0
  86. nf/cli/services/stack_inventory.py +4 -0
  87. nf/cli/state_migration.py +4 -0
  88. nf/cli/tui/__init__.py +4 -0
  89. nf/cli/tui/plan_filters.py +4 -0
  90. nf/cli/tui/plan_models.py +4 -0
  91. nf/cli/tui/plan_viewer.py +4 -0
  92. nf/cli/ui.py +4 -0
@@ -0,0 +1 @@
1
+ # netherframe.cli package
@@ -0,0 +1,4 @@
1
+ from netherframe.cli.entrypoint import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,93 @@
1
+ """NF CLI command registration.
2
+
3
+ Commands are imported only when invoked. ``nf --help`` lists them from the
4
+ static short-help text below, so it does not import every command module (and
5
+ their heavy dependencies); a test keeps that text in sync with the commands.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from importlib import import_module
11
+ from typing import NamedTuple
12
+
13
+ import click
14
+
15
+
16
+ class LazyCommand(NamedTuple):
17
+ module: str
18
+ attr: str
19
+ short_help: str
20
+
21
+
22
+ LAZY_COMMANDS: dict[str, LazyCommand] = {
23
+ "lint": LazyCommand("netherframe.cli.commands.lint", "lint", "Check all resource lints offline using installed rule packs."),
24
+ "skill": LazyCommand("netherframe.cli.commands.skill", "skill", "Read or install the bundled Netherframe skill for AI agents."),
25
+ "synth": LazyCommand("netherframe.cli.commands.synthesis", "synth", "Synthesize Netherframe applications to Terraform configuration."),
26
+ "deploy": LazyCommand("netherframe.cli.commands.synthesis", "deploy", "Deploy infrastructure (synth + init + apply)."),
27
+ "watch": LazyCommand("netherframe.cli.commands.watch_command", "watch", "Watch for file changes and re-synthesize."),
28
+ "discover": LazyCommand("netherframe.cli.commands.discover", "discover", "Discovery and introspection utilities for Netherframe."),
29
+ "providers": LazyCommand("netherframe.cli.commands.providers", "providers", "Provider package management utilities for Netherframe."),
30
+ "generate": LazyCommand("netherframe.cli.commands.generation", "generate", "Code generation utilities for Netherframe."),
31
+ "init": LazyCommand("netherframe.cli.commands.infrastructure", "init", "Initialize a stack."),
32
+ "plan": LazyCommand("netherframe.cli.commands.infrastructure", "plan", "Generate and show an execution plan for a stack or app."),
33
+ "apply": LazyCommand("netherframe.cli.commands.infrastructure", "apply", "Build or change infrastructure for a stack or app."),
34
+ "destroy": LazyCommand("netherframe.cli.commands.infrastructure", "destroy", "Destroy infrastructure for a stack or app."),
35
+ "diff": LazyCommand("netherframe.cli.commands.infrastructure", "diff", "Show a diff of planned changes (formatted plan)."),
36
+ "idiff": LazyCommand("netherframe.cli.commands.idiff", "idiff", "View infrastructure plans in an interactive TUI"),
37
+ "output": LazyCommand("netherframe.cli.commands.infrastructure", "output", "Show output values from a stack."),
38
+ "state": LazyCommand("netherframe.cli.commands.infrastructure", "state", "Advanced state management for a stack."),
39
+ "show": LazyCommand("netherframe.cli.commands.infrastructure", "show", "Show the current state or a saved plan for a stack."),
40
+ "import": LazyCommand("netherframe.cli.commands.infrastructure", "import_cmd", "Import existing infrastructure into a stack."),
41
+ "list-apps": LazyCommand("netherframe.cli.commands.infrastructure", "list_apps", "List configured legacy and hybrid apps."),
42
+ "list-stacks": LazyCommand("netherframe.cli.commands.infrastructure", "list_stacks", "List all available stacks."),
43
+ "shell": LazyCommand("netherframe.cli.commands.shell_command", "shell", "Start an interactive shell with NF context."),
44
+ "cd": LazyCommand("netherframe.cli.commands.shell_command", "cd", "Change directory to stack location."),
45
+ "convert": LazyCommand("netherframe.cli.commands.convert", "convert", "Convert a Terraform module into Netherframe Python."),
46
+ "encode": LazyCommand("netherframe.cli.commands.encode", "encode", "Add the nf_autoid coding cookie to files, directories, or glob matches."),
47
+ "config": LazyCommand("netherframe.cli.commands.config_command", "config", "Manage NF configuration."),
48
+ "init-project": LazyCommand("netherframe.cli.commands.init_command", "init", "Initialize a new NF project."),
49
+ "terraform": LazyCommand("netherframe.cli.commands.terraform_command", "terraform", "Run raw Terraform commands."),
50
+ "console": LazyCommand("netherframe.cli.commands.terraform_command", "console", "Start Terraform console."),
51
+ "backend": LazyCommand("netherframe.cli.commands.backend", "backend", "Manage backend infrastructure for state storage."),
52
+ "drift": LazyCommand("netherframe.cli.commands.drift", "drift", "Drift detection and correction commands."),
53
+ }
54
+
55
+ __all__ = ["LAZY_COMMANDS", "LazyCommand", "LazyGroup", "load_lazy_command"]
56
+
57
+
58
+ def load_lazy_command(name: str) -> click.Command:
59
+ spec = LAZY_COMMANDS[name]
60
+ command = getattr(import_module(spec.module), spec.attr)
61
+ if not isinstance(command, click.Command):
62
+ raise TypeError(f"{spec.module}.{spec.attr} is not a click command")
63
+ return command
64
+
65
+
66
+ class LazyGroup(click.Group):
67
+ """A click group whose LAZY_COMMANDS are imported on first use."""
68
+
69
+ def list_commands(self, ctx: click.Context) -> list[str]:
70
+ return sorted({*super().list_commands(ctx), *LAZY_COMMANDS})
71
+
72
+ def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None:
73
+ command = super().get_command(ctx, cmd_name)
74
+ if command is None and cmd_name in LAZY_COMMANDS:
75
+ command = load_lazy_command(cmd_name)
76
+ self.add_command(command, cmd_name)
77
+ return command
78
+
79
+ def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
80
+ rows: list[tuple[str, str]] = []
81
+ limit = formatter.width - 6 - max((len(name) for name in self.list_commands(ctx)), default=0)
82
+ for name in self.list_commands(ctx):
83
+ loaded = self.commands.get(name)
84
+ if loaded is not None:
85
+ if loaded.hidden:
86
+ continue
87
+ rows.append((name, loaded.get_short_help_str(limit)))
88
+ else:
89
+ # A help-only placeholder lets click truncate the text without importing the command
90
+ rows.append((name, click.Command(name, help=LAZY_COMMANDS[name].short_help).get_short_help_str(limit)))
91
+ if rows:
92
+ with formatter.section("Commands"):
93
+ formatter.write_dl(rows)
@@ -0,0 +1,305 @@
1
+ """Backend management commands for Netherframe CLI."""
2
+
3
+ from netherframe.core.serialization import orjson_compat as json
4
+ from pathlib import Path
5
+
6
+ import click
7
+ from netherframe.core.backends.backend_chain import (
8
+ BackendBootstrapAction,
9
+ build_backend_chain_from_config,
10
+ )
11
+ from netherframe.core.backends.backend_config import BackendAutoDetector, BackendConfigManager
12
+ from netherframe.core.constructs.backend_base import Backend
13
+ from netherframe.core.logging import get_logger
14
+ from netherframe.cli.ui import console
15
+ from rich.table import Table
16
+
17
+ logger = get_logger(__name__)
18
+
19
+
20
+ @click.group()
21
+ def backend() -> None:
22
+ """Manage backend infrastructure for state storage."""
23
+
24
+
25
+ @backend.command()
26
+ @click.option(
27
+ "--project-name",
28
+ "-p",
29
+ help="Project name for resource naming",
30
+ )
31
+ @click.option(
32
+ "--type",
33
+ "-t",
34
+ "backend_type",
35
+ type=click.Choice(["s3", "gcs", "azurerm", "local"]),
36
+ help="Backend type to configure",
37
+ )
38
+ @click.option(
39
+ "--auto-detect/--no-auto-detect",
40
+ default=True,
41
+ help="Auto-detect backend configuration based on environment",
42
+ )
43
+ @click.option(
44
+ "--save/--no-save",
45
+ default=True,
46
+ help="Save configuration for future use",
47
+ )
48
+ def configure(
49
+ project_name: str | None,
50
+ backend_type: str | None,
51
+ auto_detect: bool,
52
+ save: bool,
53
+ ) -> None:
54
+ """Configure backend for the project."""
55
+ console.print("[bold blue]Configuring backend...[/bold blue]")
56
+
57
+ if backend_type and not auto_detect:
58
+ # Manual configuration
59
+ if backend_type == "s3":
60
+ bucket = click.prompt("S3 bucket name")
61
+ region = click.prompt("AWS region", default="us-east-1")
62
+ encrypt = click.confirm("Enable encryption?", default=True)
63
+ use_dynamodb = click.confirm(
64
+ "Use DynamoDB for state locking?",
65
+ default=True,
66
+ )
67
+
68
+ dynamodb_table = None
69
+ if use_dynamodb:
70
+ dynamodb_table = click.prompt(
71
+ "DynamoDB table name",
72
+ default=f"nf-state-lock-{bucket}",
73
+ )
74
+
75
+ from netherframe.core.backends.backend_config import BackendConfig
76
+
77
+ config = BackendConfig(
78
+ backend_type="s3",
79
+ config={
80
+ "bucket": bucket,
81
+ "key": "terraform.tfstate",
82
+ "region": region,
83
+ "encrypt": encrypt,
84
+ "dynamodb_table": dynamodb_table,
85
+ },
86
+ auto_bootstrap=True,
87
+ )
88
+ else:
89
+ console.print(
90
+ f"[red]Manual configuration for {backend_type} not yet implemented[/red]",
91
+ )
92
+ return
93
+ else:
94
+ # Auto-detect configuration
95
+ config = BackendAutoDetector.detect(project_name)
96
+
97
+ if not config:
98
+ console.print("[red]Failed to auto-detect backend configuration[/red]")
99
+ return
100
+
101
+ # Display configuration
102
+ table = Table(title="Backend Configuration")
103
+ table.add_column("Setting", style="cyan")
104
+ table.add_column("Value", style="green")
105
+
106
+ table.add_row("Type", config.backend_type)
107
+ for key, value in config.config.items():
108
+ if value is not None:
109
+ table.add_row(key.replace("_", " ").title(), str(value))
110
+ table.add_row("Auto Bootstrap", str(config.auto_bootstrap))
111
+
112
+ console.print(table)
113
+
114
+ if save:
115
+ BackendConfigManager.save_config(config)
116
+ console.print("[green]✓ Configuration saved[/green]")
117
+
118
+
119
+ @backend.command()
120
+ @click.option(
121
+ "--config-file",
122
+ "-c",
123
+ type=click.Path(exists=True, path_type=Path),
124
+ help="Path to backend configuration file",
125
+ )
126
+ @click.option(
127
+ "--force/--no-force",
128
+ default=False,
129
+ help="Force creation even if resources exist",
130
+ )
131
+ @click.option(
132
+ "--dry-run/--no-dry-run",
133
+ default=False,
134
+ help="Show what would be created without actually creating",
135
+ )
136
+ def bootstrap(config_file: Path | None, force: bool, dry_run: bool) -> None:
137
+ """Bootstrap backend infrastructure resources."""
138
+ console.print("[bold blue]Bootstrapping backend resources...[/bold blue]")
139
+
140
+ # Load configuration
141
+ if config_file:
142
+ with Path(config_file).open() as f:
143
+ config_data = json.load(f)
144
+ from netherframe.core.backends.backend_config import BackendConfig
145
+
146
+ config = BackendConfig(**config_data)
147
+ else:
148
+ config = BackendConfigManager.load_config()
149
+ if not config:
150
+ console.print(
151
+ "[yellow]No saved configuration found. Running auto-detection...[/yellow]",
152
+ )
153
+ config = BackendAutoDetector.detect()
154
+
155
+ if not config:
156
+ console.print("[red]No backend configuration available[/red]")
157
+ return
158
+
159
+ # Build backend chain from config and run bootstrap
160
+ try:
161
+ chain = build_backend_chain_from_config(
162
+ config=config,
163
+ include_local_fallback=False,
164
+ register=False,
165
+ )
166
+ except ValueError as exc:
167
+ raise click.ClickException(str(exc)) from exc
168
+
169
+ policy = Backend.BootstrapPolicy.ALWAYS if force else Backend.BootstrapPolicy.IF_MISSING
170
+ result = chain.bootstrap_resources(policy=policy, dry_run=dry_run)
171
+
172
+ backend_label = result.backend.backend_type if result.backend is not None else config.backend_type
173
+
174
+ if result.action is BackendBootstrapAction.UNSUPPORTED:
175
+ console.print(
176
+ f"[red]Bootstrap not supported for {backend_label}: {result.reason}[/red]",
177
+ )
178
+ return
179
+
180
+ if result.action is BackendBootstrapAction.SKIPPED:
181
+ console.print(
182
+ f"[yellow]Bootstrap skipped for {backend_label}: {result.reason}[/yellow]",
183
+ )
184
+ return
185
+
186
+ if result.action is BackendBootstrapAction.ALREADY_EXISTS:
187
+ console.print(
188
+ f"[green]✓ {backend_label} backend resources already exist[/green]",
189
+ )
190
+ return
191
+
192
+ if result.action is BackendBootstrapAction.DRY_RUN:
193
+ console.print("[yellow]DRY RUN - No resources will be created[/yellow]")
194
+ console.print(f"{backend_label}: {result.reason}")
195
+ return
196
+
197
+ if result.action is BackendBootstrapAction.BOOTSTRAPPED:
198
+ resources = result.resources
199
+ if resources is not None:
200
+ resource_data = resources.to_dict()
201
+ if resource_data:
202
+ table = Table(title="Created Resources")
203
+ table.add_column("Resource", style="cyan")
204
+ table.add_column("Name/ID", style="green")
205
+ for key, value in resource_data.items():
206
+ table.add_row(key.replace("_", " ").title(), str(value))
207
+ console.print(table)
208
+
209
+ console.print(
210
+ f"[green]✓ {backend_label} backend resources bootstrapped successfully[/green]",
211
+ )
212
+
213
+
214
+ @backend.command()
215
+ @click.option(
216
+ "--config-file",
217
+ "-c",
218
+ type=click.Path(exists=True, path_type=Path),
219
+ help="Path to backend configuration file",
220
+ )
221
+ def validate(config_file: Path | None) -> None:
222
+ """Validate that backend resources exist and are accessible."""
223
+ console.print("[bold blue]Validating backend resources...[/bold blue]")
224
+
225
+ # Load configuration
226
+ if config_file:
227
+ with Path(config_file).open() as f:
228
+ config_data = json.load(f)
229
+ from netherframe.core.backends.backend_config import BackendConfig
230
+
231
+ config = BackendConfig(**config_data)
232
+ else:
233
+ config = BackendConfigManager.load_config()
234
+
235
+ if not config:
236
+ console.print("[red]No backend configuration found[/red]")
237
+ return
238
+
239
+ try:
240
+ chain = build_backend_chain_from_config(
241
+ config=config,
242
+ include_local_fallback=False,
243
+ register=False,
244
+ )
245
+ except ValueError as exc:
246
+ raise click.ClickException(str(exc)) from exc
247
+
248
+ result = chain.bootstrap_resources(
249
+ policy=Backend.BootstrapPolicy.IF_MISSING,
250
+ dry_run=True,
251
+ )
252
+
253
+ backend_label = result.backend.backend_type if result.backend is not None else config.backend_type
254
+
255
+ if result.action is BackendBootstrapAction.UNSUPPORTED:
256
+ console.print(
257
+ f"[yellow]Validation not implemented for {backend_label}: {result.reason}[/yellow]",
258
+ )
259
+ return
260
+
261
+ if result.action is BackendBootstrapAction.ALREADY_EXISTS:
262
+ console.print(
263
+ f"[green]✓ {backend_label} backend resources are valid and accessible[/green]",
264
+ )
265
+ return
266
+
267
+ console.print("[red]✗ Backend validation failed[/red]")
268
+ console.print(f"{backend_label}: {result.reason}")
269
+ console.print("Run 'nf backend bootstrap' to create missing resources")
270
+
271
+
272
+ @backend.command()
273
+ def show() -> None:
274
+ """Show current backend configuration."""
275
+ config = BackendConfigManager.load_config()
276
+
277
+ if not config:
278
+ console.print("[yellow]No saved backend configuration found[/yellow]")
279
+ console.print("Run 'nf backend configure' to set up a backend")
280
+ return
281
+
282
+ # Display configuration
283
+ table = Table(title="Current Backend Configuration")
284
+ table.add_column("Setting", style="cyan")
285
+ table.add_column("Value", style="green")
286
+
287
+ table.add_row("Type", config.backend_type)
288
+ for key, value in config.config.items():
289
+ if value is not None:
290
+ table.add_row(key.replace("_", " ").title(), str(value))
291
+ table.add_row("Auto Bootstrap", str(config.auto_bootstrap))
292
+
293
+ if config.bootstrap_tags:
294
+ tags_str = ", ".join(f"{k}={v}" for k, v in config.bootstrap_tags.items())
295
+ table.add_row("Bootstrap Tags", tags_str)
296
+
297
+ console.print(table)
298
+
299
+ # Show config file location
300
+ config_path = BackendConfigManager.get_config_path()
301
+ console.print(f"\nConfiguration file: {config_path}")
302
+
303
+
304
+ if __name__ == "__main__":
305
+ backend()
@@ -0,0 +1,98 @@
1
+ """Configuration command for NF CLI."""
2
+
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ import click
7
+
8
+ from netherframe.core.config import find_pyproject_toml, get_cached_tool_nf_config
9
+
10
+
11
+ def find_config_file() -> str | None:
12
+ """Find pyproject.toml using shared netherframe.core config discovery."""
13
+ pyproject = find_pyproject_toml()
14
+ return str(pyproject) if pyproject else None
15
+
16
+
17
+ def load_config() -> dict[str, Any]:
18
+ """Load NF configuration from pyproject.toml."""
19
+ config_path = find_config_file()
20
+ if not config_path:
21
+ return {}
22
+
23
+ try:
24
+ return get_cached_tool_nf_config(config_path)
25
+ except Exception as e:
26
+ click.echo(f"Error loading config: {e}", err=True)
27
+ return {}
28
+
29
+
30
+ @click.group()
31
+ def config() -> None:
32
+ """Manage NF configuration."""
33
+
34
+
35
+ @config.command()
36
+ def show() -> None:
37
+ """Show current configuration."""
38
+ config_data = load_config()
39
+
40
+ if not config_data:
41
+ click.echo("No NF configuration found in pyproject.toml")
42
+ return
43
+
44
+ click.echo("[tool.nf]")
45
+ for key, value in config_data.items():
46
+ if isinstance(value, (list, dict)):
47
+ click.echo(f"{key} = {value!r}")
48
+ else:
49
+ click.echo(f"{key} = {value!r}")
50
+
51
+
52
+ @config.command()
53
+ @click.argument("key")
54
+ def get(key: str) -> None:
55
+ """Get a specific configuration value."""
56
+ config_data = load_config()
57
+
58
+ if key not in config_data:
59
+ click.echo(f"Key '{key}' not found in configuration", err=True)
60
+ click.get_current_context().exit(1)
61
+
62
+ value = config_data[key]
63
+ if isinstance(value, list):
64
+ for item in value:
65
+ click.echo(item)
66
+ else:
67
+ click.echo(value)
68
+
69
+
70
+ @config.command()
71
+ def validate() -> None:
72
+ """Validate the configuration."""
73
+ config_data = load_config()
74
+
75
+ if not config_data:
76
+ click.echo("No NF configuration found")
77
+ return
78
+
79
+ # Basic validation - check if app files exist
80
+ apps = config_data.get("legacy_apps", [])
81
+ all_valid = True
82
+
83
+ for app_ref in apps:
84
+ if ":" in app_ref:
85
+ module_path, _ = app_ref.split(":", 1)
86
+ if module_path.endswith(".py"):
87
+ file_path = Path(module_path)
88
+ else:
89
+ file_path = Path(module_path.replace(".", "/") + ".py")
90
+
91
+ if not file_path.exists():
92
+ click.echo(f"Error: App file not found: {file_path}", err=True)
93
+ all_valid = False
94
+
95
+ if all_valid:
96
+ click.echo("Configuration is valid")
97
+ else:
98
+ click.get_current_context().exit(1)
@@ -0,0 +1,40 @@
1
+ """``nf convert``: turn a Terraform module into Netherframe Python (see netherframe.generation.convert)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import click
8
+
9
+
10
+ @click.command(name="convert")
11
+ @click.argument("module_dir", type=click.Path(exists=True, file_okay=False, path_type=Path))
12
+ @click.option("-o", "--output", type=click.Path(file_okay=False, path_type=Path), default=Path(), show_default=True, help="Directory to write the package into.")
13
+ @click.option("--package", help="Name of the Python package to write (default: the module directory's name).")
14
+ @click.option("--generic", is_flag=True, help="Write generic Resource(nf_type=...) constructs even for providers with generated bindings installed.")
15
+ @click.option("--force", is_flag=True, help="Replace the package directory if it exists.")
16
+ @click.option("--no-format", is_flag=True, help="Do not format the written code with Ruff.")
17
+ @click.option("--fetch-modules", is_flag=True, help="Download public registry modules and HTTPS/GitHub archives for conversion (without Terraform).")
18
+ @click.option("--module-cache", type=click.Path(file_okay=False, path_type=Path), help="Cache for downloaded module sources.")
19
+ @click.option("--report", type=click.Path(dir_okay=False, path_type=Path), help="Also write the conversion report to this file.")
20
+ def convert(module_dir: Path, output: Path, package: str | None, generic: bool, force: bool, no_format: bool, report: Path | None, fetch_modules: bool, module_cache: Path | None) -> None:
21
+ """Convert a Terraform module into Netherframe Python.
22
+
23
+ Reads the module's .tf and .tf.json files and the local modules it calls, and writes a Python
24
+ package: a Stack subclass for the module, a class per local module, typed constructs of the
25
+ installed generated provider packages. What it cannot convert is marked
26
+ `# TODO(nf convert): ...` with the original HCL.
27
+ """
28
+ from netherframe.generation.convert import ConversionError, HclSyntaxError, convert_module
29
+
30
+ try:
31
+ result = convert_module(module_dir, output, package=package, use_generated_bindings=not generic, format_code=not no_format, clean=force, fetch_modules=fetch_modules, module_cache=module_cache)
32
+ except (ConversionError, HclSyntaxError) as error:
33
+ raise click.ClickException(str(error)) from error
34
+ text = result.report()
35
+ click.echo(text, nl=False)
36
+ click.echo(f"\nWrote {len(result.files)} files to {result.output}")
37
+ if not no_format and not result.formatted:
38
+ click.echo("Ruff was not available: the code is not formatted", err=True)
39
+ if report is not None:
40
+ report.write_text(text)