code: def cmdline_example_to_rst(src, out=None, ref=None):
      if out is None:
          from io import StringIO
  
          out = StringIO()
  
      # place header
      out.write(".. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n")
      if ref:
          # place cross-ref target
          out.write(".. {0}:\n\n".format(ref))
  
      # parser status vars
      inexample = False
      incodeblock = False
  
      for line in src:
          if line.startswith("#% EXAMPLE START"):
              inexample = True
              incodeblock = False
              continue
          if not inexample:
              continue
          if line.startswith("#% EXAMPLE END"):
              break
          if not inexample:
              continue
          if line.startswith("#%"):
              incodeblock = not incodeblock
              if incodeblock:
                  out.write("\n.. code-block:: sh\n\n")
              continue
          if not incodeblock and line.startswith("#"):
              out.write(line[(min(2, len(line) - 1)) :])
              continue
          if incodeblock:
              if not line.rstrip().endswith("#% SKIP"):
                  out.write("  %s" % line)
              continue
          if not len(line.strip()):
              continue
          else:
              raise RuntimeError("this should not happen")
  
      return out
  
imports: import argparse
  import datetime
  import os
  import re
  import time
  from textwrap import wrap
label_desc: Use image node_id 1 for calling a global function with example usage: cmdline_example_to_rst(src, out, ref) and returns: out