anydi 0.67.2__py3-none-any.whl → 0.69.0__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.
anydi/_cli.py ADDED
@@ -0,0 +1,80 @@
1
+ """AnyDI CLI module."""
2
+
3
+ import argparse
4
+ import sys
5
+
6
+ from anydi import import_container
7
+
8
+
9
+ def main() -> None:
10
+ """CLI entry point."""
11
+ parser = argparse.ArgumentParser(description="AnyDI CLI")
12
+ parser.add_argument(
13
+ "container",
14
+ help="Path to the container instance or factory (e.g., 'module:container')",
15
+ )
16
+ parser.add_argument(
17
+ "--app-dir",
18
+ default="",
19
+ help="Look for APP in the specified directory, by adding this to the "
20
+ "PYTHONPATH. Defaults to the current working directory.",
21
+ )
22
+ parser.add_argument(
23
+ "--output-format",
24
+ "-o",
25
+ choices=["tree", "mermaid", "dot", "json"],
26
+ default="tree",
27
+ help="Output format for the dependency graph",
28
+ )
29
+ parser.add_argument(
30
+ "--full-path",
31
+ action="store_true",
32
+ help="Show full module path for dependencies",
33
+ )
34
+ parser.add_argument(
35
+ "--indent",
36
+ "-i",
37
+ type=int,
38
+ default=2,
39
+ help="JSON indentation level",
40
+ )
41
+ parser.add_argument(
42
+ "--scan",
43
+ "-s",
44
+ nargs="+",
45
+ help="Packages or modules to scan for dependencies",
46
+ )
47
+
48
+ args = parser.parse_args()
49
+
50
+ if args.app_dir is not None:
51
+ sys.path.insert(0, args.app_dir)
52
+
53
+ try:
54
+ container = import_container(args.container)
55
+ except (ImportError, ValueError) as exc:
56
+ print(f"Error: {exc}", file=sys.stderr) # noqa: T201
57
+ sys.exit(1)
58
+
59
+ if args.scan:
60
+ try:
61
+ container.scan(args.scan)
62
+ except Exception as exc:
63
+ print(f"Error scanning packages: {exc}", file=sys.stderr) # noqa: T201
64
+ sys.exit(1)
65
+
66
+ try:
67
+ graph_out = container.graph(
68
+ output_format=args.output_format,
69
+ full_path=args.full_path,
70
+ ident=args.indent,
71
+ )
72
+ except (LookupError, ValueError, TypeError) as exc:
73
+ print(f"Error: {exc}", file=sys.stderr) # noqa: T201
74
+ sys.exit(1)
75
+
76
+ print(graph_out) # noqa: T201
77
+
78
+
79
+ if __name__ == "__main__":
80
+ main()