Skip to content

Commit d0eae0b

Browse files
gijzelaerrclaude
andcommitted
Export discover_command for s7 CLI integration
Exports a reusable click command (discover_command) that the s7 CLI can auto-register as `s7 discover`. Removes the standalone snap7-scan entry point in favor of the unified s7 CLI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 357fc8e commit d0eae0b

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ include = ["snap7*"]
4545

4646
[project.scripts]
4747
snap7-server = "snap7.server:mainloop"
48-
snap7-scan = "snap7.discovery:main"
4948

5049
[tool.pytest.ini_options]
5150
testpaths = ["tests"]

snap7/discovery.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,13 @@ def identify(ip: str, mac: str) -> Device:
104104
)
105105

106106

107-
def main() -> None:
108-
"""CLI entry point for snap7-scan."""
109-
try:
110-
import click
111-
except ImportError:
112-
print("CLI dependencies not installed. Try: pip install python-snap7[cli]")
113-
raise
107+
try:
108+
import click
114109

115110
@click.command()
116111
@click.argument("ip")
117112
@click.option("--timeout", type=float, default=5.0, help="Discovery timeout in seconds.")
118-
def scan(ip: str, timeout: float) -> None:
113+
def discover_command(ip: str, timeout: float) -> None:
119114
"""Discover PROFINET devices on the network.
120115
121116
IP is the address of the local network interface to use for discovery.
@@ -138,7 +133,13 @@ def scan(ip: str, timeout: float) -> None:
138133
for device in devices:
139134
click.echo(f" {device.name:<30s} {device.ip:<16s} {device.mac}")
140135

141-
scan()
136+
except ImportError:
137+
pass
138+
139+
140+
def main() -> None:
141+
"""Standalone CLI entry point for discovery."""
142+
discover_command()
142143

143144

144145
if __name__ == "__main__":

0 commit comments

Comments
 (0)