panorama-super-cli 0.2.2__tar.gz → 0.2.3__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 (95) hide show
  1. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/CHANGELOG.md +14 -0
  2. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/PKG-INFO +1 -1
  3. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/guides/output-formats.md +19 -0
  4. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/guides/safety.md +10 -0
  5. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/reference/cli.md +8 -6
  6. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/_version.py +1 -1
  7. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/_plan.py +27 -2
  8. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/dedup_cmds.py +5 -3
  9. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/name_cmds.py +12 -5
  10. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/source.py +47 -2
  11. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/pyproject.toml +1 -1
  12. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/skills/panorama-super-cli/SKILL.md +16 -2
  13. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_cli.py +45 -0
  14. panorama_super_cli-0.2.3/tests/test_source.py +62 -0
  15. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/uv.lock +577 -577
  16. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.github/CODEOWNERS +0 -0
  17. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  18. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  19. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  20. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.github/dependabot.yml +0 -0
  21. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.github/workflows/docs.yml +0 -0
  22. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.github/workflows/lint.yml +0 -0
  23. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.github/workflows/release.yml +0 -0
  24. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.github/workflows/test.yml +0 -0
  25. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.gitignore +0 -0
  26. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.pre-commit-config.yaml +0 -0
  27. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/.python-version +0 -0
  28. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/AGENTS.md +0 -0
  29. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/CLAUDE.md +0 -0
  30. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/LICENSE +0 -0
  31. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/README.md +0 -0
  32. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/contributing/branching.md +0 -0
  33. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/contributing/development.md +0 -0
  34. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/contributing/release-process.md +0 -0
  35. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/getting-started/concepts.md +0 -0
  36. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/getting-started/first-run.md +0 -0
  37. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/getting-started/install.md +0 -0
  38. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/guides/duplicates-and-merging.md +0 -0
  39. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/guides/finding-objects.md +0 -0
  40. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/guides/live-vs-offline.md +0 -0
  41. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/guides/naming.md +0 -0
  42. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/guides/references-and-audit.md +0 -0
  43. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/guides/using-with-ai-agents.md +0 -0
  44. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/index.md +0 -0
  45. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/reference/config.md +0 -0
  46. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/docs/reference/exit-codes.md +0 -0
  47. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/justfile +0 -0
  48. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/mkdocs.yml +0 -0
  49. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/__init__.py +0 -0
  50. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/__main__.py +0 -0
  51. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/__init__.py +0 -0
  52. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/app.py +0 -0
  53. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/auth_cmds.py +0 -0
  54. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/find_cmds.py +0 -0
  55. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/profile_cmds.py +0 -0
  56. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/refs_cmds.py +0 -0
  57. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/cli/runtime.py +0 -0
  58. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/config/__init__.py +0 -0
  59. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/config/loader.py +0 -0
  60. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/config/models.py +0 -0
  61. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/__init__.py +0 -0
  62. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/apply_live.py +0 -0
  63. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/apply_xml.py +0 -0
  64. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/changeset.py +0 -0
  65. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/dedup.py +0 -0
  66. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/models.py +0 -0
  67. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/naming.py +0 -0
  68. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/normalize.py +0 -0
  69. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/parse.py +0 -0
  70. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/refs.py +0 -0
  71. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/resolve.py +0 -0
  72. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/core/setcmd.py +0 -0
  73. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/output/__init__.py +0 -0
  74. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/output/errors.py +0 -0
  75. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/psc/output/format.py +0 -0
  76. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/scripts/sync_agents_md.py +0 -0
  77. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/__init__.py +0 -0
  78. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/conftest.py +0 -0
  79. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/fixtures/nested-device-groups.xml +0 -0
  80. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/fixtures/panorama-config.xml +0 -0
  81. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_apply_xml.py +0 -0
  82. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_auth.py +0 -0
  83. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_changeset.py +0 -0
  84. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_cli_auth.py +0 -0
  85. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_dedup.py +0 -0
  86. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_hardening.py +0 -0
  87. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_live_apply.py +0 -0
  88. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_naming.py +0 -0
  89. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_nested_dg.py +0 -0
  90. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_normalize.py +0 -0
  91. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_output.py +0 -0
  92. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_parse.py +0 -0
  93. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_refs.py +0 -0
  94. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_resolve.py +0 -0
  95. {panorama_super_cli-0.2.2 → panorama_super_cli-0.2.3}/tests/test_setcmd.py +0 -0
@@ -7,6 +7,20 @@ project will follow [Semantic Versioning](https://semver.org/). While on
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## v0.2.3 — 2026-06-04
11
+
12
+ ### Added
13
+
14
+ - **`-of` / `--output-format xml|set` for the offline `--apply --out` artifact.**
15
+ Mutating commands (`dedup merge`, `name rename`, `name apply`) can now write the
16
+ rewritten config file as the equivalent PAN-OS `set` script instead of XML.
17
+ `xml` (the rewritten, `load config`-able config) stays the default, so existing
18
+ invocations are unchanged; `set` writes the creates/deletes/repoints that
19
+ achieve the same change, which is easier to read and to paste into a config
20
+ session or `load config partial`. This is distinct from `-o set`, which renders
21
+ the dry-run plan to stdout. The blocker hard-gate and repoint-before-delete
22
+ ordering apply to both formats; a blocked plan writes no file. (#37)
23
+
10
24
  ## v0.2.2 — 2026-06-04
11
25
 
12
26
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: panorama-super-cli
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Agent-friendly CLI for Palo Alto Panorama object management: find, dedup/merge, rename, and audit address/service objects safely.
5
5
  Project-URL: Homepage, https://github.com/thomaschristory/panorama-super-cli
6
6
  Project-URL: Documentation, https://thomaschristory.github.io/panorama-super-cli/
@@ -50,6 +50,25 @@ Member-list edits become `delete` + `set` because PAN-OS `set` on a member field
50
50
  can't safely render (NAT translation paths) appear as `# REVIEW` comments; the
51
51
  structured (`json`) plan still carries them.
52
52
 
53
+ ### `-o set` (stdout) vs `--output-format set` (the `--out` file)
54
+
55
+ These are two different knobs and it's worth keeping them straight:
56
+
57
+ - **`-o set`** controls what a command prints to **stdout** — use it to read or
58
+ pipe the plan during a dry-run.
59
+ - **`-of` / `--output-format`** (offline mutating commands only) controls the
60
+ format of the **`--apply --out` file artifact**: `xml` (default) rewrites the
61
+ whole config to load with `load config`, while `set` writes the same PAN-OS
62
+ `set` script shown above to that file — easier to read and to paste into a
63
+ config session or `load config partial`.
64
+
65
+ ```console
66
+ psc -c panorama.xml dedup merge --keep h-web1 --remove web-primary --apply --out plan.set -of set
67
+ ```
68
+
69
+ `-of` only shapes the file and is ignored without `--apply`; on a live profile
70
+ there is no file artifact, so it has no effect there.
71
+
53
72
  ## Errors
54
73
 
55
74
  Errors are emitted as a stable JSON envelope:
@@ -46,6 +46,16 @@ psc -c panorama.xml dedup merge --keep a --remove b --apply --out fixed.xml
46
46
  diff <(xmllint --format panorama.xml) <(xmllint --format fixed.xml)
47
47
  ```
48
48
 
49
+ By default the `--out` file is the rewritten config XML. Pass
50
+ `-of/--output-format set` to instead write the equivalent PAN-OS `set` script
51
+ (the creates/deletes/repoints that achieve the same change) — easier to read and
52
+ to paste into a config session. The blocker gate and repoint-before-delete
53
+ ordering apply to both formats identically; a blocked plan writes no file.
54
+
55
+ ```console
56
+ psc -c panorama.xml dedup merge --keep a --remove b --apply --out plan.set -of set
57
+ ```
58
+
49
59
  ## Live writes
50
60
 
51
61
  Live `--apply` pushes the plan to Panorama's **candidate** config over the XML
@@ -17,9 +17,11 @@ These are **context** options — pass them *before* the subcommand:
17
17
  | `--debug` | Verbose structured logs on stderr. |
18
18
  | `--version` | Print version and exit. |
19
19
 
20
- Write-execution options (`--apply`, `--out`) belong to the individual mutating
21
- commands and are passed *after* the command. `--apply` is the only path to a
22
- write; offline it requires `--out PATH` (a new file), while live it pushes to
20
+ Write-execution options (`--apply`, `--out`, `-of/--output-format`) belong to
21
+ the individual mutating commands and are passed *after* the command. `--apply`
22
+ is the only path to a write; offline it requires `--out PATH` (a new file) and
23
+ `-of xml|set` chooses what that file holds (default `xml`), while live it pushes
24
+ to
23
25
  Panorama's candidate config and never commits. See
24
26
  [Writes and safety](../guides/safety.md).
25
27
 
@@ -42,7 +44,7 @@ psc dedup addresses
42
44
  psc dedup services
43
45
  psc dedup merge --keep NAME --remove NAME [--location LOC]
44
46
  [--keep-location LOC] [--remove-location LOC]
45
- [--allow-value-change] [--apply] [--out PATH]
47
+ [--allow-value-change] [--apply] [--out PATH] [-of xml|set]
46
48
  ```
47
49
 
48
50
  Find duplicates; merge one object into another, repointing all references. See
@@ -63,8 +65,8 @@ Where-used, recursive unused, and dangling-reference audit. See
63
65
 
64
66
  ```
65
67
  psc name lint [--all]
66
- psc name rename --object OLD --to NEW [--kind KIND] [--location LOC] [--apply] [--out PATH]
67
- psc name apply --object NAME [--location LOC] [--apply] [--out PATH]
68
+ psc name rename --object OLD --to NEW [--kind KIND] [--location LOC] [--apply] [--out PATH] [-of xml|set]
69
+ psc name apply --object NAME [--location LOC] [--apply] [--out PATH] [-of xml|set]
68
70
  ```
69
71
 
70
72
  Opt-in naming-template lint and reference-aware rename. See
@@ -4,4 +4,4 @@
4
4
  Keep this in sync with `[project].version` in `pyproject.toml`.
5
5
  """
6
6
 
7
- __version__ = "0.2.2"
7
+ __version__ = "0.2.3"
@@ -7,14 +7,39 @@ refused, dry-run is the default, and `--apply` is the only path to a write.
7
7
 
8
8
  from __future__ import annotations
9
9
 
10
+ import typer
11
+
10
12
  from psc.cli.runtime import Runtime
11
13
  from psc.core.changeset import ChangeSet
12
14
  from psc.core.setcmd import render_changeset
15
+ from psc.core.source import ConfigFormat
13
16
  from psc.output.errors import ErrorType, PscError
14
17
  from psc.output.format import OutputFormat, render
15
18
 
19
+ # Shared across every mutating command so the `--out` artifact toggle reads and
20
+ # behaves identically wherever `complete()` is used (dedup merge, name rename,
21
+ # name apply). Default `xml` keeps existing scripts byte-for-byte compatible.
22
+ OUT_FORMAT_OPTION = typer.Option(
23
+ ConfigFormat.XML,
24
+ "--output-format",
25
+ "-of",
26
+ help=(
27
+ "Format of the offline --out artifact. 'xml' (default) rewrites the whole "
28
+ "config to load with `load config`; 'set' writes the equivalent PAN-OS set "
29
+ "script (the creates/deletes/repoints) — easier to read and to paste into a "
30
+ "config session. Only affects --out; ignored without --apply."
31
+ ),
32
+ )
33
+
16
34
 
17
- def complete(rt: Runtime, cs: ChangeSet, *, apply: bool, out_path: str | None) -> None:
35
+ def complete(
36
+ rt: Runtime,
37
+ cs: ChangeSet,
38
+ *,
39
+ apply: bool,
40
+ out_path: str | None,
41
+ out_format: ConfigFormat = ConfigFormat.XML,
42
+ ) -> None:
18
43
  """Render `cs` in the chosen format, then apply it iff `apply`.
19
44
 
20
45
  A blocked plan raises `CONFLICT` (exit 6) before any write. The structured
@@ -43,7 +68,7 @@ def complete(rt: Runtime, cs: ChangeSet, *, apply: bool, out_path: str | None) -
43
68
  return
44
69
 
45
70
  if apply:
46
- result = rt.source().apply(cs, out_path=out_path)
71
+ result = rt.source().apply(cs, out_path=out_path, out_format=out_format)
47
72
  rt.stderr.print(
48
73
  f"[green]applied[/green] {result.ops} operation(s)"
49
74
  + (f" → {result.out_path}" if result.out_path else "")
@@ -4,7 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import typer
6
6
 
7
- from psc.cli._plan import complete
7
+ from psc.cli._plan import OUT_FORMAT_OPTION, complete
8
8
  from psc.cli.runtime import Runtime
9
9
  from psc.core.dedup import (
10
10
  DuplicateGroup,
@@ -14,6 +14,7 @@ from psc.core.dedup import (
14
14
  plan_merge,
15
15
  )
16
16
  from psc.core.refs import ReferenceGraph
17
+ from psc.core.source import ConfigFormat
17
18
  from psc.output.errors import ErrorType, PscError
18
19
  from psc.output.format import render
19
20
 
@@ -71,8 +72,9 @@ def merge(
71
72
  ),
72
73
  apply: bool = typer.Option(False, "--apply", help="Execute the merge (default: dry-run)."),
73
74
  out: str | None = typer.Option(
74
- None, "--out", help="Offline: write the rewritten config XML here."
75
+ None, "--out", help="Offline: write the rewritten config here (see --output-format)."
75
76
  ),
77
+ output_format: ConfigFormat = OUT_FORMAT_OPTION,
76
78
  ) -> None:
77
79
  """Collapse one address object into another, repointing every reference.
78
80
 
@@ -91,4 +93,4 @@ def merge(
91
93
  drop=ObjectRef(name=remove, location=remove_location or default_loc),
92
94
  allow_value_change=allow_value_change,
93
95
  )
94
- complete(rt, cs, apply=apply, out_path=out)
96
+ complete(rt, cs, apply=apply, out_path=out, out_format=output_format)
@@ -4,12 +4,13 @@ from __future__ import annotations
4
4
 
5
5
  import typer
6
6
 
7
- from psc.cli._plan import complete
7
+ from psc.cli._plan import OUT_FORMAT_OPTION, complete
8
8
  from psc.cli.runtime import Runtime
9
9
  from psc.core.changeset import ObjectKind
10
10
  from psc.core.naming import lint as lint_engine
11
11
  from psc.core.naming import plan_rename
12
12
  from psc.core.refs import ReferenceGraph
13
+ from psc.core.source import ConfigFormat
13
14
  from psc.output.errors import ErrorType, PscError
14
15
  from psc.output.format import render
15
16
 
@@ -49,7 +50,10 @@ def rename(
49
50
  kind: ObjectKind = typer.Option(ObjectKind.ADDRESS, "--kind"),
50
51
  location: str | None = typer.Option(None, "--location"),
51
52
  apply: bool = typer.Option(False, "--apply", help="Execute the rename (default: dry-run)."),
52
- out: str | None = typer.Option(None, "--out", help="Offline: write rewritten config XML here."),
53
+ out: str | None = typer.Option(
54
+ None, "--out", help="Offline: write rewritten config here (see --output-format)."
55
+ ),
56
+ output_format: ConfigFormat = OUT_FORMAT_OPTION,
53
57
  ) -> None:
54
58
  """Rename one object, repointing every reference (refuses on shadow collisions)."""
55
59
  rt: Runtime = ctx.obj
@@ -57,7 +61,7 @@ def rename(
57
61
  snap = rt.snapshot()
58
62
  graph = ReferenceGraph.build(snap)
59
63
  cs = plan_rename(snap, graph, kind=kind, location_name=loc, old_name=object_name, new_name=to)
60
- complete(rt, cs, apply=apply, out_path=out)
64
+ complete(rt, cs, apply=apply, out_path=out, out_format=output_format)
61
65
 
62
66
 
63
67
  @app.command("apply")
@@ -66,7 +70,10 @@ def apply_scheme(
66
70
  object_name: str = typer.Option(..., "--object", help="Object to rename to its scheme name."),
67
71
  location: str | None = typer.Option(None, "--location"),
68
72
  apply: bool = typer.Option(False, "--apply", help="Execute the rename (default: dry-run)."),
69
- out: str | None = typer.Option(None, "--out", help="Offline: write rewritten config XML here."),
73
+ out: str | None = typer.Option(
74
+ None, "--out", help="Offline: write rewritten config here (see --output-format)."
75
+ ),
76
+ output_format: ConfigFormat = OUT_FORMAT_OPTION,
70
77
  ) -> None:
71
78
  """Rename one object to the name the configured scheme implies for its value."""
72
79
  rt: Runtime = ctx.obj
@@ -98,4 +105,4 @@ def apply_scheme(
98
105
  cs = plan_rename(
99
106
  snap, graph, kind=kind, location_name=loc, old_name=object_name, new_name=suggested
100
107
  )
101
- complete(rt, cs, apply=apply, out_path=out)
108
+ complete(rt, cs, apply=apply, out_path=out, out_format=output_format)
@@ -18,6 +18,7 @@ Writes are deliberately conservative:
18
18
  from __future__ import annotations
19
19
 
20
20
  import ssl
21
+ from enum import Enum
21
22
  from pathlib import Path
22
23
 
23
24
  from pydantic import BaseModel, Field
@@ -26,9 +27,23 @@ from psc.core.apply_xml import apply_changeset
26
27
  from psc.core.changeset import ChangeSet
27
28
  from psc.core.models import Snapshot
28
29
  from psc.core.parse import parse_config
30
+ from psc.core.setcmd import render_changeset
29
31
  from psc.output.errors import ErrorType, PscError
30
32
 
31
33
 
34
+ class ConfigFormat(str, Enum):
35
+ """Format of the artifact an offline `apply` writes to `--out`.
36
+
37
+ `xml` rewrites the whole exported config (loadable with `load config`);
38
+ `set` emits the equivalent PAN-OS `set` script (the creations/deletes/
39
+ repoints that achieve the same change) — easier to read and to paste into a
40
+ config session or `load config partial`.
41
+ """
42
+
43
+ XML = "xml"
44
+ SET = "set"
45
+
46
+
32
47
  class ApplyResult(BaseModel):
33
48
  applied: bool
34
49
  ops: int
@@ -83,7 +98,13 @@ class OfflineSource:
83
98
  except Exception as exc:
84
99
  raise PscError(f"failed to parse {self.path}: {exc}", ErrorType.INPUT) from exc
85
100
 
86
- def apply(self, cs: ChangeSet, *, out_path: str | Path | None) -> ApplyResult:
101
+ def apply(
102
+ self,
103
+ cs: ChangeSet,
104
+ *,
105
+ out_path: str | Path | None,
106
+ out_format: ConfigFormat = ConfigFormat.XML,
107
+ ) -> ApplyResult:
87
108
  if out_path is None:
88
109
  raise PscError(
89
110
  "offline apply needs --out PATH (the rewritten config is never "
@@ -93,6 +114,20 @@ class OfflineSource:
93
114
  out = Path(out_path)
94
115
  if out.resolve() == self.path.resolve():
95
116
  raise PscError("--out must differ from the source config path", ErrorType.CONFIG)
117
+ # The blocker gate is enforced here for *every* format — the XML path
118
+ # relies on `apply_changeset`, but the set path renders the plan without
119
+ # it, so refuse before writing rather than emit a `# BLOCKED` file.
120
+ if cs.is_blocked:
121
+ raise PscError(
122
+ "refusing to apply a blocked plan",
123
+ ErrorType.CONFLICT,
124
+ details={"blockers": cs.blockers},
125
+ )
126
+ # Both artifacts share the same safety guards above; only the bytes differ.
127
+ if out_format is ConfigFormat.SET:
128
+ script = render_changeset(cs)
129
+ out.write_text("\n".join(script) + "\n", encoding="utf-8")
130
+ return ApplyResult(applied=True, ops=cs.op_count, out_path=str(out), set_script=script)
96
131
  new_xml = apply_changeset(self._xml, cs)
97
132
  out.write_text(new_xml, encoding="utf-8")
98
133
  return ApplyResult(applied=True, ops=cs.op_count, out_path=str(out))
@@ -221,9 +256,19 @@ class LiveSource:
221
256
  def snapshot(self) -> Snapshot:
222
257
  return parse_config(self.raw_xml())
223
258
 
224
- def apply(self, cs: ChangeSet, *, out_path: str | Path | None) -> ApplyResult:
259
+ def apply(
260
+ self,
261
+ cs: ChangeSet,
262
+ *,
263
+ out_path: str | Path | None,
264
+ out_format: ConfigFormat = ConfigFormat.XML,
265
+ ) -> ApplyResult:
225
266
  """Push `cs` to Panorama's candidate config over the XML API.
226
267
 
268
+ `out_path`/`out_format` are accepted for interface parity with the
269
+ offline source but ignored — a live apply leaves a candidate on the
270
+ device, not a file, so there is no artifact to format.
271
+
227
272
  The plan is lowered to xpath set/edit/delete/rename ops and replayed in
228
273
  order (repoint before delete). The `blockers` gate and name-addressing
229
274
  check run *before* any device contact, so a refused plan never writes.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "panorama-super-cli"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  description = "Agent-friendly CLI for Palo Alto Panorama object management: find, dedup/merge, rename, and audit address/service objects safely."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -29,7 +29,8 @@ psc [GLOBAL OPTS] <group> <command> [ARGS] [WRITE OPTS]
29
29
  - **Global (context) options go *before* the group:** `-c/--config FILE`,
30
30
  `-p/--profile NAME`, `-o/--output FMT`, `-d/--device-group NAME`, `--strict`,
31
31
  `--debug`.
32
- - **Write-execution options go *after* the command:** `--apply`, `--out PATH`.
32
+ - **Write-execution options go *after* the command:** `--apply`, `--out PATH`,
33
+ `-of/--output-format xml|set`.
33
34
 
34
35
  ```bash
35
36
  psc -c panorama.xml -o json find ip 10.0.0.10
@@ -39,7 +40,20 @@ psc -c panorama.xml dedup merge --keep h-web1 --remove web-primary --apply --out
39
40
  ## Pick a source
40
41
 
41
42
  - **Offline:** `-c panorama.xml` — an exported config. Read-only against the
42
- device; `--apply` writes a *new* file via `--out`.
43
+ device; `--apply` writes a *new* file via `--out` (it never overwrites the
44
+ source export). Choose what that file holds with `-of/--output-format`:
45
+ - `xml` (default) — the whole config rewritten, loadable with `load config`.
46
+ - `set` — just the equivalent PAN-OS `set` script (the creates/deletes/
47
+ repoints that achieve the change). Easier to read and to paste into a
48
+ config session or `load config partial`. Use this when a human reviews the
49
+ change or you want a minimal, diff-like artifact; use `xml` when you need a
50
+ full, directly-loadable replacement config.
51
+
52
+ ```bash
53
+ psc -c cfg.xml dedup merge --keep a --remove b --apply --out plan.set -of set
54
+ ```
55
+ (`-of` only shapes the `--out` file; for the script on stdout in a dry-run,
56
+ use `-o set` instead.)
43
57
  - **Live:** `-p prod` — fetches the running config over the XML API. `--apply`
44
58
  (no `--out`) pushes the plan to Panorama's **candidate** config and never
45
59
  commits; you review and commit yourself.
@@ -122,6 +122,51 @@ def test_merge_apply_writes_out(tmp_path: Path) -> None:
122
122
  assert "web-primary" not in out.read_text(encoding="utf-8")
123
123
 
124
124
 
125
+ def test_merge_apply_out_set_writes_set_script(tmp_path: Path) -> None:
126
+ out = tmp_path / "fixed.set"
127
+ cp = run(
128
+ "-c",
129
+ str(FIXTURE),
130
+ "dedup",
131
+ "merge",
132
+ "--keep",
133
+ "h-web1",
134
+ "--remove",
135
+ "web-primary",
136
+ "--apply",
137
+ "--out",
138
+ str(out),
139
+ "-of",
140
+ "set",
141
+ )
142
+ assert cp.returncode == 0
143
+ assert out.exists()
144
+ text = out.read_text(encoding="utf-8")
145
+ assert "delete shared address web-primary" in text
146
+ assert "<entry" not in text # the --out artifact is a set script, not XML
147
+
148
+
149
+ def test_merge_apply_out_xml_is_default(tmp_path: Path) -> None:
150
+ out = tmp_path / "fixed.xml"
151
+ cp = run(
152
+ "-c",
153
+ str(FIXTURE),
154
+ "dedup",
155
+ "merge",
156
+ "--keep",
157
+ "h-web1",
158
+ "--remove",
159
+ "web-primary",
160
+ "--apply",
161
+ "--out",
162
+ str(out),
163
+ "--output-format",
164
+ "xml",
165
+ )
166
+ assert cp.returncode == 0
167
+ assert "web-primary" not in out.read_text(encoding="utf-8") # rewritten XML, object gone
168
+
169
+
125
170
  def test_no_source_errors_config() -> None:
126
171
  cp = run("-o", "json", "find", "ip", "10.0.0.10")
127
172
  assert cp.returncode == 9
@@ -0,0 +1,62 @@
1
+ """Offline `apply` artifact-format behaviour (#37: write `set` script instead of XML)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import pytest
8
+
9
+ from psc.core.changeset import ChangeSet, ObjectDelete, ObjectKind
10
+ from psc.core.source import ConfigFormat, OfflineSource
11
+ from psc.output.errors import PscError
12
+
13
+ FIXTURE = Path(__file__).parent / "fixtures" / "panorama-config.xml"
14
+
15
+
16
+ def _delete_cs() -> ChangeSet:
17
+ return ChangeSet(
18
+ title="t",
19
+ deletes=[ObjectDelete(kind=ObjectKind.ADDRESS, name="web-primary", location="shared")],
20
+ )
21
+
22
+
23
+ def test_apply_set_format_writes_set_script_not_xml(tmp_path: Path) -> None:
24
+ out = tmp_path / "plan.set"
25
+ res = OfflineSource(FIXTURE).apply(_delete_cs(), out_path=out, out_format=ConfigFormat.SET)
26
+ text = out.read_text(encoding="utf-8")
27
+ assert "delete shared address web-primary" in text
28
+ assert "<entry" not in text # the artifact is a set script, never XML
29
+ assert res.set_script # the rendered lines ride back on the result
30
+ assert res.out_path == str(out)
31
+
32
+
33
+ def test_apply_xml_format_is_the_default(tmp_path: Path) -> None:
34
+ out = tmp_path / "fixed.xml"
35
+ res = OfflineSource(FIXTURE).apply(_delete_cs(), out_path=out)
36
+ text = out.read_text(encoding="utf-8")
37
+ assert "<" in text # still rewritten XML when no format is asked for
38
+ assert not res.set_script
39
+
40
+
41
+ def test_apply_set_format_still_refuses_overwriting_source() -> None:
42
+ with pytest.raises(PscError):
43
+ OfflineSource(FIXTURE).apply(_delete_cs(), out_path=FIXTURE, out_format=ConfigFormat.SET)
44
+
45
+
46
+ def test_apply_set_format_still_requires_out_path() -> None:
47
+ with pytest.raises(PscError):
48
+ OfflineSource(FIXTURE).apply(_delete_cs(), out_path=None, out_format=ConfigFormat.SET)
49
+
50
+
51
+ def test_apply_set_format_refuses_blocked_plan_and_writes_nothing(tmp_path: Path) -> None:
52
+ # The blocker gate is enforced at the applier level for every format, not
53
+ # only in the CLI — a blocked plan must never reach a written artifact.
54
+ out = tmp_path / "plan.set"
55
+ blocked = ChangeSet(
56
+ title="t",
57
+ blockers=["cross-scope reference can't be repointed"],
58
+ deletes=[ObjectDelete(kind=ObjectKind.ADDRESS, name="web-primary", location="shared")],
59
+ )
60
+ with pytest.raises(PscError):
61
+ OfflineSource(FIXTURE).apply(blocked, out_path=out, out_format=ConfigFormat.SET)
62
+ assert not out.exists()