netherframe.cli 0.2.1__tar.gz

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-0.2.1/LICENSE +21 -0
  2. netherframe_cli-0.2.1/PKG-INFO +86 -0
  3. netherframe_cli-0.2.1/README.md +53 -0
  4. netherframe_cli-0.2.1/netherframe/cli/__init__.py +1 -0
  5. netherframe_cli-0.2.1/netherframe/cli/__main__.py +4 -0
  6. netherframe_cli-0.2.1/netherframe/cli/commands/__init__.py +93 -0
  7. netherframe_cli-0.2.1/netherframe/cli/commands/backend.py +305 -0
  8. netherframe_cli-0.2.1/netherframe/cli/commands/config_command.py +98 -0
  9. netherframe_cli-0.2.1/netherframe/cli/commands/convert.py +40 -0
  10. netherframe_cli-0.2.1/netherframe/cli/commands/discover.py +679 -0
  11. netherframe_cli-0.2.1/netherframe/cli/commands/drift.py +499 -0
  12. netherframe_cli-0.2.1/netherframe/cli/commands/encode.py +130 -0
  13. netherframe_cli-0.2.1/netherframe/cli/commands/generation.py +861 -0
  14. netherframe_cli-0.2.1/netherframe/cli/commands/graph_state.py +439 -0
  15. netherframe_cli-0.2.1/netherframe/cli/commands/hybrid.py +461 -0
  16. netherframe_cli-0.2.1/netherframe/cli/commands/idiff.py +493 -0
  17. netherframe_cli-0.2.1/netherframe/cli/commands/infrastructure.py +1182 -0
  18. netherframe_cli-0.2.1/netherframe/cli/commands/init_command.py +11 -0
  19. netherframe_cli-0.2.1/netherframe/cli/commands/lint.py +49 -0
  20. netherframe_cli-0.2.1/netherframe/cli/commands/providers.py +315 -0
  21. netherframe_cli-0.2.1/netherframe/cli/commands/shell_command.py +17 -0
  22. netherframe_cli-0.2.1/netherframe/cli/commands/skill.py +167 -0
  23. netherframe_cli-0.2.1/netherframe/cli/commands/synthesis.py +732 -0
  24. netherframe_cli-0.2.1/netherframe/cli/commands/terraform_command.py +17 -0
  25. netherframe_cli-0.2.1/netherframe/cli/commands/watch_command.py +117 -0
  26. netherframe_cli-0.2.1/netherframe/cli/entrypoint.py +18 -0
  27. netherframe_cli-0.2.1/netherframe/cli/logging.py +33 -0
  28. netherframe_cli-0.2.1/netherframe/cli/main.py +177 -0
  29. netherframe_cli-0.2.1/netherframe/cli/options.py +32 -0
  30. netherframe_cli-0.2.1/netherframe/cli/py.typed +0 -0
  31. netherframe_cli-0.2.1/netherframe/cli/services/__init__.py +1 -0
  32. netherframe_cli-0.2.1/netherframe/cli/services/app_loader.py +62 -0
  33. netherframe_cli-0.2.1/netherframe/cli/services/app_resolver.py +205 -0
  34. netherframe_cli-0.2.1/netherframe/cli/services/graph_onboarding.py +144 -0
  35. netherframe_cli-0.2.1/netherframe/cli/services/legacy_cli.py +51 -0
  36. netherframe_cli-0.2.1/netherframe/cli/services/project_config.py +107 -0
  37. netherframe_cli-0.2.1/netherframe/cli/services/provider_batch.py +620 -0
  38. netherframe_cli-0.2.1/netherframe/cli/services/stack_inventory.py +342 -0
  39. netherframe_cli-0.2.1/netherframe/cli/skills/netherframe/SKILL.md +53 -0
  40. netherframe_cli-0.2.1/netherframe/cli/skills/netherframe/agents/openai.yaml +3 -0
  41. netherframe_cli-0.2.1/netherframe/cli/skills/netherframe/references/authoring.md +77 -0
  42. netherframe_cli-0.2.1/netherframe/cli/skills/netherframe/references/execution.md +70 -0
  43. netherframe_cli-0.2.1/netherframe/cli/skills/netherframe/references/migration.md +69 -0
  44. netherframe_cli-0.2.1/netherframe/cli/state_migration.py +111 -0
  45. netherframe_cli-0.2.1/netherframe/cli/tui/__init__.py +1 -0
  46. netherframe_cli-0.2.1/netherframe/cli/tui/plan_filters.py +200 -0
  47. netherframe_cli-0.2.1/netherframe/cli/tui/plan_models.py +51 -0
  48. netherframe_cli-0.2.1/netherframe/cli/tui/plan_viewer.py +745 -0
  49. netherframe_cli-0.2.1/netherframe/cli/ui.py +25 -0
  50. netherframe_cli-0.2.1/nf/cli/__init__.py +4 -0
  51. netherframe_cli-0.2.1/nf/cli/__main__.py +4 -0
  52. netherframe_cli-0.2.1/nf/cli/commands/__init__.py +4 -0
  53. netherframe_cli-0.2.1/nf/cli/commands/backend.py +4 -0
  54. netherframe_cli-0.2.1/nf/cli/commands/config_command.py +4 -0
  55. netherframe_cli-0.2.1/nf/cli/commands/convert.py +4 -0
  56. netherframe_cli-0.2.1/nf/cli/commands/discover.py +4 -0
  57. netherframe_cli-0.2.1/nf/cli/commands/drift.py +4 -0
  58. netherframe_cli-0.2.1/nf/cli/commands/encode.py +4 -0
  59. netherframe_cli-0.2.1/nf/cli/commands/generation.py +4 -0
  60. netherframe_cli-0.2.1/nf/cli/commands/graph_state.py +4 -0
  61. netherframe_cli-0.2.1/nf/cli/commands/hybrid.py +4 -0
  62. netherframe_cli-0.2.1/nf/cli/commands/idiff.py +4 -0
  63. netherframe_cli-0.2.1/nf/cli/commands/infrastructure.py +4 -0
  64. netherframe_cli-0.2.1/nf/cli/commands/init_command.py +4 -0
  65. netherframe_cli-0.2.1/nf/cli/commands/lint.py +4 -0
  66. netherframe_cli-0.2.1/nf/cli/commands/providers.py +4 -0
  67. netherframe_cli-0.2.1/nf/cli/commands/shell_command.py +4 -0
  68. netherframe_cli-0.2.1/nf/cli/commands/skill.py +4 -0
  69. netherframe_cli-0.2.1/nf/cli/commands/synthesis.py +4 -0
  70. netherframe_cli-0.2.1/nf/cli/commands/terraform_command.py +4 -0
  71. netherframe_cli-0.2.1/nf/cli/commands/watch_command.py +4 -0
  72. netherframe_cli-0.2.1/nf/cli/entrypoint.py +4 -0
  73. netherframe_cli-0.2.1/nf/cli/logging.py +4 -0
  74. netherframe_cli-0.2.1/nf/cli/main.py +4 -0
  75. netherframe_cli-0.2.1/nf/cli/options.py +4 -0
  76. netherframe_cli-0.2.1/nf/cli/py.typed +0 -0
  77. netherframe_cli-0.2.1/nf/cli/services/__init__.py +4 -0
  78. netherframe_cli-0.2.1/nf/cli/services/app_loader.py +4 -0
  79. netherframe_cli-0.2.1/nf/cli/services/app_resolver.py +4 -0
  80. netherframe_cli-0.2.1/nf/cli/services/graph_onboarding.py +4 -0
  81. netherframe_cli-0.2.1/nf/cli/services/legacy_cli.py +4 -0
  82. netherframe_cli-0.2.1/nf/cli/services/project_config.py +4 -0
  83. netherframe_cli-0.2.1/nf/cli/services/provider_batch.py +4 -0
  84. netherframe_cli-0.2.1/nf/cli/services/stack_inventory.py +4 -0
  85. netherframe_cli-0.2.1/nf/cli/state_migration.py +4 -0
  86. netherframe_cli-0.2.1/nf/cli/tui/__init__.py +4 -0
  87. netherframe_cli-0.2.1/nf/cli/tui/plan_filters.py +4 -0
  88. netherframe_cli-0.2.1/nf/cli/tui/plan_models.py +4 -0
  89. netherframe_cli-0.2.1/nf/cli/tui/plan_viewer.py +4 -0
  90. netherframe_cli-0.2.1/nf/cli/ui.py +4 -0
  91. netherframe_cli-0.2.1/pyproject.toml +78 -0
  92. netherframe_cli-0.2.1/pyproject.toml.orig +73 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Netherframe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: netherframe.cli
3
+ Version: 0.2.1
4
+ Summary: Netherframe CLI - Command-line interface for Netherframe
5
+ Author: Sourabh Cheedella
6
+ Author-email: Sourabh Cheedella <cheedella.sourabh@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3.14
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Classifier: Topic :: System :: Systems Administration
14
+ Classifier: Environment :: Console
15
+ Requires-Dist: netherframe-core>=0.9.0
16
+ Requires-Dist: netherframe-generation>=0.3.0
17
+ Requires-Dist: netherframe-legacy-functions-hashicorp-terraform
18
+ Requires-Dist: click>=8.5.1
19
+ Requires-Dist: rich>=15.0.0
20
+ Requires-Dist: textual>=8.2.8
21
+ Requires-Dist: questionary>=2.1.1
22
+ Requires-Dist: watchdog>=7.1.0
23
+ Requires-Dist: pyyaml>=6.0.3
24
+ Requires-Dist: tomli-w>=1.2.0
25
+ Requires-Dist: urllib3>=2.8.0
26
+ Requires-Dist: pytest>=9.2.0 ; extra == 'dev'
27
+ Requires-Dist: pytest-mock>=3.17.0 ; extra == 'dev'
28
+ Requires-Python: >=3.14
29
+ Project-URL: Homepage, https://netherframe.arsenal.sh
30
+ Project-URL: Repository, https://github.com/arsenal-sh/netherframe
31
+ Provides-Extra: dev
32
+ Description-Content-Type: text/markdown
33
+
34
+ # netherframe.cli
35
+
36
+ The `nf` command-line interface for Netherframe, a Python infrastructure as code
37
+ framework using Terraform providers. Netherframe is **pre-1.0** and requires
38
+ Python **3.14+**.
39
+
40
+ ## Install in your app's environment
41
+
42
+ ```bash
43
+ uv add netherframe.cli
44
+ source .venv/bin/activate
45
+ nf --version
46
+ nf --help
47
+ ```
48
+
49
+ Or use `python -m pip install netherframe.cli` in an activated environment, then
50
+ run `nf --help`. The CLI installs core, generation support and the Terraform
51
+ legacy-function catalogue. Add your provider bindings and optional backend,
52
+ discovery or lint packages separately. Keep them in the same environment that
53
+ loads your Python app.
54
+
55
+ The dotted distribution name is `netherframe.cli`; the executable is `nf`.
56
+ Python code can import `nf.cli` or its canonical name `netherframe.cli`.
57
+
58
+ ## Workflows
59
+
60
+ - `nf plan --app` and `nf apply --app` run providers directly in the recommended hybrid workflow.
61
+ - `nf synth` exports Terraform-compatible configuration for existing Terraform/OpenTofu pipelines.
62
+ - `nf generate providers`: generate typed Python provider bindings.
63
+ - `nf convert` and `nf discover`: migration and resource-discovery tooling.
64
+ - `nf state` and `nf backend`: state inspection, recovery and backend tooling.
65
+ - `nf lint`: explicit offline checks through installed policy packs.
66
+ - `nf skill`: read/install the bundled guidance for AI agents.
67
+
68
+ For compatibility, an explicit synthesized stack directory selects the external
69
+ Terraform/OpenTofu CLI. Provider binaries and remote-service credentials
70
+ are separate from the Python CLI installation. Installing a policy pack does not
71
+ automatically run linting during a plan or apply.
72
+
73
+ ## Documentation and support
74
+
75
+ - [Installation and source checkout](https://github.com/arsenal-sh/netherframe/blob/main/docs/getting-started/installation.md)
76
+ - [Tutorials](https://github.com/arsenal-sh/netherframe/blob/main/docs/tutorials/README.md)
77
+ - [Compatibility](https://github.com/arsenal-sh/netherframe/blob/main/docs/operations/compatibility.md)
78
+ - [Release notes](https://github.com/arsenal-sh/netherframe/blob/main/docs/operations/release-notes.md)
79
+ - [Support](https://github.com/arsenal-sh/netherframe/blob/main/SUPPORT.md)
80
+
81
+ The planned homepage is https://netherframe.arsenal.sh. Until the repository and
82
+ site are publicly available, use the documentation in a source checkout. Report
83
+ suspected vulnerabilities privately to **cheedella.sourabh@gmail.com**.
84
+
85
+ Netherframe-owned code is MIT licensed; see the bundled `LICENSE`. Dependencies
86
+ retain their own licenses.
@@ -0,0 +1,53 @@
1
+ # netherframe.cli
2
+
3
+ The `nf` command-line interface for Netherframe, a Python infrastructure as code
4
+ framework using Terraform providers. Netherframe is **pre-1.0** and requires
5
+ Python **3.14+**.
6
+
7
+ ## Install in your app's environment
8
+
9
+ ```bash
10
+ uv add netherframe.cli
11
+ source .venv/bin/activate
12
+ nf --version
13
+ nf --help
14
+ ```
15
+
16
+ Or use `python -m pip install netherframe.cli` in an activated environment, then
17
+ run `nf --help`. The CLI installs core, generation support and the Terraform
18
+ legacy-function catalogue. Add your provider bindings and optional backend,
19
+ discovery or lint packages separately. Keep them in the same environment that
20
+ loads your Python app.
21
+
22
+ The dotted distribution name is `netherframe.cli`; the executable is `nf`.
23
+ Python code can import `nf.cli` or its canonical name `netherframe.cli`.
24
+
25
+ ## Workflows
26
+
27
+ - `nf plan --app` and `nf apply --app` run providers directly in the recommended hybrid workflow.
28
+ - `nf synth` exports Terraform-compatible configuration for existing Terraform/OpenTofu pipelines.
29
+ - `nf generate providers`: generate typed Python provider bindings.
30
+ - `nf convert` and `nf discover`: migration and resource-discovery tooling.
31
+ - `nf state` and `nf backend`: state inspection, recovery and backend tooling.
32
+ - `nf lint`: explicit offline checks through installed policy packs.
33
+ - `nf skill`: read/install the bundled guidance for AI agents.
34
+
35
+ For compatibility, an explicit synthesized stack directory selects the external
36
+ Terraform/OpenTofu CLI. Provider binaries and remote-service credentials
37
+ are separate from the Python CLI installation. Installing a policy pack does not
38
+ automatically run linting during a plan or apply.
39
+
40
+ ## Documentation and support
41
+
42
+ - [Installation and source checkout](https://github.com/arsenal-sh/netherframe/blob/main/docs/getting-started/installation.md)
43
+ - [Tutorials](https://github.com/arsenal-sh/netherframe/blob/main/docs/tutorials/README.md)
44
+ - [Compatibility](https://github.com/arsenal-sh/netherframe/blob/main/docs/operations/compatibility.md)
45
+ - [Release notes](https://github.com/arsenal-sh/netherframe/blob/main/docs/operations/release-notes.md)
46
+ - [Support](https://github.com/arsenal-sh/netherframe/blob/main/SUPPORT.md)
47
+
48
+ The planned homepage is https://netherframe.arsenal.sh. Until the repository and
49
+ site are publicly available, use the documentation in a source checkout. Report
50
+ suspected vulnerabilities privately to **cheedella.sourabh@gmail.com**.
51
+
52
+ Netherframe-owned code is MIT licensed; see the bundled `LICENSE`. Dependencies
53
+ retain their own licenses.
@@ -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)