fix(cli): silence info and warnings in --list mode, add -q/-v flags, bump version to 1.0.1
Build and Publish Release / Build Packages and Publish (push) Successful in 9s
Build and Publish Release / Build Packages and Publish (push) Successful in 9s
This commit is contained in:
1 parent
e19a4303f8
commit
5fedc44c6b
6 files changed
+64
-21
No files matched your search
@@ -86,6 +86,16 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
action="store_true",
|
||||
help="Synchronize inventory to both Ansible and linux-connector default paths."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-q", "--quiet",
|
||||
action="store_true",
|
||||
help="Silence all informational and warning messages on stderr."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v", "--verbose",
|
||||
action="store_true",
|
||||
help="Enable verbose output (forces logs even in --list mode)."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-c", "--config",
|
||||
type=Path,
|
||||
@@ -127,15 +137,19 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
else:
|
||||
verify_ssl = app_config.proxmox.verify_ssl
|
||||
|
||||
is_quiet = args.quiet or (args.list and not args.verbose)
|
||||
|
||||
if pve_url and pve_token_id and pve_token_secret:
|
||||
sys.stderr.write(f"[INFO] Querying Proxmox VE API at {pve_url}...\n")
|
||||
if not is_quiet:
|
||||
sys.stderr.write(f"[INFO] Querying Proxmox VE API at {pve_url}...\n")
|
||||
pve_collector = ProxmoxCollector(
|
||||
url=pve_url,
|
||||
token_id=pve_token_id,
|
||||
token_secret=pve_token_secret,
|
||||
verify_ssl=verify_ssl,
|
||||
timeout=app_config.proxmox.timeout,
|
||||
default_user=app_config.default_ssh_user
|
||||
default_user=app_config.default_ssh_user,
|
||||
quiet=is_quiet
|
||||
)
|
||||
raw_records.extend(pve_collector.collect())
|
||||
|
||||
@@ -162,12 +176,14 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
engine = DeduplicationEngine(conflict_policy=app_config.conflict_policy)
|
||||
inv, warnings = engine.process(raw_records)
|
||||
|
||||
for w in warnings:
|
||||
sys.stderr.write(f"[WARN] {w}\n")
|
||||
if not is_quiet:
|
||||
for w in warnings:
|
||||
sys.stderr.write(f"[WARN] {w}\n")
|
||||
|
||||
# 5. Inspection / Dry-run Mode
|
||||
if args.dry_run:
|
||||
sys.stderr.write(f"[INFO] Discovered {len(inv.hosts)} hosts across {len(inv.groups)} groups.\n")
|
||||
if not is_quiet:
|
||||
sys.stderr.write(f"[INFO] Discovered {len(inv.hosts)} hosts across {len(inv.groups)} groups.\n")
|
||||
print("NAME IP ADDRESS SOURCE GROUPS")
|
||||
for h in inv.hosts.values():
|
||||
groups_str = ", ".join(h.groups)
|
||||
@@ -185,10 +201,12 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
lc_dest = (app_config.output_linux_connector or Path("~/.config/linux-connector/hosts.yaml")).expanduser()
|
||||
|
||||
AnsibleYamlExporter().write_to_file(inv, ansible_dest)
|
||||
sys.stderr.write(f"[SUCCESS] Updated Ansible inventory: {ansible_dest}\n")
|
||||
if not is_quiet:
|
||||
sys.stderr.write(f"[SUCCESS] Updated Ansible inventory: {ansible_dest}\n")
|
||||
|
||||
LinuxConnectorExporter().write_to_file(inv, lc_dest)
|
||||
sys.stderr.write(f"[SUCCESS] Updated linux-connector inventory: {lc_dest}\n")
|
||||
if not is_quiet:
|
||||
sys.stderr.write(f"[SUCCESS] Updated linux-connector inventory: {lc_dest}\n")
|
||||
return 0
|
||||
|
||||
# 8. Standard Format Export
|
||||
@@ -204,7 +222,8 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
|
||||
if args.output:
|
||||
exporter.write_to_file(inv, args.output)
|
||||
sys.stderr.write(f"[SUCCESS] Written {fmt} inventory to {args.output}\n")
|
||||
if not is_quiet:
|
||||
sys.stderr.write(f"[SUCCESS] Written {fmt} inventory to {args.output}\n")
|
||||
else:
|
||||
sys.stdout.write(rendered)
|
||||
|
||||
|
||||
Reference in new issue
Block a user