code: def main():
      parser = argparse.ArgumentParser()
      parser.add_argument(
          "--add",
          nargs=2,
          action="append",
          default=[],
          metavar=("IP", "DOMAIN"),
          help="Add entry to hosts file",
      )
      parser.add_argument(
          "--add-k3d-registry",
          action="store_true",
          default=False,
          help="Add entry for k3d-registry.localhost",
      )
      parser.add_argument(
          "--fix-docker-hosts",
          action="store_true",
          default=False,
          help="Windows - Fix *.docker.internal. Linux/macOS - remove them",
      )
      parser.add_argument(
          "--disable-wsl2-auto-hosts",
          action="store_true",
          default=False,
          dest="wsl2_disable_auto_hosts",
          help="[Optional] Disable automatic /etc/hosts generation from Windows in WSL2",
      )
      parser.add_argument(
          "--hosts",
          type=Path,
          default=None,
          help="[Optional] Path to a hosts-like file",
      )
  
      if len(sys.argv) < 2:
          parser.print_help()
          sys.exit(1)
  
      args = parser.parse_args()
  
      if not args.hosts and not running_as_root():
          print(
              "ERROR: This script must be run as root since it will modify system hosts file"
          )
          sys.exit(1)
  
      hosts = Hosts(args.hosts)
  
      print(">> Args", args.__dict__)
      print(">> OS:", Platform.system)
      print(">> Release:", Platform.uname.release)
      print(">> Version:", Platform.uname.version)
      print(">> Hosts file:", hosts.path)
  
      if len(args.add):
          for ip, domain in args.add:
              print(f">> Adding {ip} {domain}")
              hosts.update(ip, domain)
  
      if args.add_k3d_registry:
          print(">> Adding k3d registry host entry")
          hosts.update("127.0.0.1", "k3d-registry.localhost")
  
      if args.fix_docker_hosts:
          if Platform.windows() or Platform.wsl2():
              print(">> Fixing docker host entries for Windows/WSL2")
              hosts.update("0.0.0.0", "host.docker.internal")
              hosts.update("0.0.0.0", "gateway.docker.internal")
              hosts.update("127.0.0.1", "kubernetes.docker.internal")
          else:
              print(">> Removing docker host entries")
              hosts.remove("host.docker.internal")
              hosts.remove("gateway.docker.internal")
              hosts.remove("kubernetes.docker.internal")
  
      if args.wsl2_disable_auto_hosts and Platform.wsl2():
          print(">> Disabling auto hosts generation")
          wsl2_disable_auto_hosts()
  
      print(">> Done")
      print("-" * 50)
      print(hosts.read())
      print("-" * 50)
  
imports: import argparse
  from functools import cached_property
  import os
  from pathlib import Path
  import platform
  import re
  import sys
label_desc: Use image node_id 3 for calling a global function with example usage: main() without return types