code: def main() -> None:
      
  
      # Make sure we have access to self
      if 'self' not in globals():
          print("Run 'set locals_in_py true' and then rerun this script")
          return
  
      # Make sure the user passed in an output file
      if len(sys.argv) != 2:
          print("Usage: {} <output_file>".format(os.path.basename(sys.argv[0])))
          return
  
      # Open the output file
      outfile_path = os.path.expanduser(sys.argv[1])
      try:
          outfile = open(outfile_path, 'w')
      except OSError as e:
          print("Error opening {} because: {}".format(outfile_path, e))
          return
  
      # Write the help summary
      header = '{0}\nSUMMARY\n{0}\n'.format(ASTERISKS)
      outfile.write(header)
  
      result = app('help -v')
      outfile.write(result.stdout)
  
      # Get a list of all commands and help topics and then filter out duplicates
      all_commands = set(self.get_all_commands())
      all_topics = set(self.get_help_topics())
      to_save = list(all_commands | all_topics)
      to_save.sort()
  
      for item in to_save:
          is_command = item in all_commands
          add_help_to_file(item, outfile, is_command)
  
          if is_command:
              # Add any sub-commands
              for subcmd in get_sub_commands(getattr(self.cmd_func(item), 'argparser', None)):
                  full_cmd = '{} {}'.format(item, subcmd)
                  add_help_to_file(full_cmd, outfile, is_command)
  
      outfile.close()
      print("Output written to {}".format(outfile_path))
docs: Main function of this script