def process_arguments() -> Namespace:
    """Process command-line arguments.

    Create a basic command-line parser through :func:`~patroni.daemon.get_base_arg_parser`, extend its capabilities by
    adding these flags and parse command-line arguments.:

      * ``--validate-config`` -- used to validate the Patroni configuration file
      * ``--generate-config`` -- used to generate Patroni configuration from a running PostgreSQL instance
      * ``--generate-sample-config`` -- used to generate a sample Patroni configuration
      * ``--ignore-listen-port`` | ``-i`` -- used to ignore ``listen`` ports already in use.
          Can be used only with ``--validate-config``
      * ``--print`` | ``-p`` -- used to print out local configuration (incl. environment configuration overrides).
          Can be used only with ``--validate-config``

    .. note::
        If running with ``--generate-config``, ``--generate-sample-config`` or ``--validate-flag`` will exit
        after generating or validating configuration.

    :returns: parsed arguments, if not running with ``--validate-config`` flag.
    """
    from patroni.config_generator import generate_config

    parser = get_base_arg_parser()
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--validate-config', action='store_true', help='Run config validator and exit')
    group.add_argument('--generate-sample-config', action='store_true',
                       help='Generate a sample Patroni yaml configuration file')
    group.add_argument('--generate-config', action='store_true',
                       help='Generate a Patroni yaml configuration file for a running instance')
    parser.add_argument('--dsn', help='Optional DSN string of the instance to be used as a source \
                                    for config generation. Superuser connection is required.')
    parser.add_argument('--ignore-listen-port', '-i', action='store_true',
                        help='Ignore `listen` ports already in use.\
                              Can only be used with --validate-config')
    parser.add_argument('--print', '-p', action='store_true',
                        help='Print out local configuration (incl. environment configuration overrides).\
                              Can only be used with --validate-config')
    args = parser.parse_args()

    if args.generate_sample_config:
        generate_config(args.configfile, True, None)
        sys.exit(0)
    elif args.generate_config:
        generate_config(args.configfile, False, args.dsn)
        sys.exit(0)
    elif args.validate_config:
        from patroni.config import Config, ConfigParseError
        from patroni.validator import populate_validate_params, schema

        populate_validate_params(ignore_listen_port=args.ignore_listen_port)

        try:
            config = Config(args.configfile, validator=schema)
        except ConfigParseError as e:
            sys.exit(e.value)

        if args.print:
            import yaml
            yaml.safe_dump(config.local_configuration, sys.stdout, default_flow_style=False, allow_unicode=True)
        sys.exit()

    return args
Process command-line arguments.

    Create a basic command-line parser through :func:`~patroni.daemon.get_base_arg_parser`, extend its capabilities by
    adding these flags and parse command-line arguments.:

      * ``--validate-config`` -- used to validate the Patroni configuration file
      * ``--generate-config`` -- used to generate Patroni configuration from a running PostgreSQL instance
      * ``--generate-sample-config`` -- used to generate a sample Patroni configuration
      * ``--ignore-listen-port`` | ``-i`` -- used to ignore ``listen`` ports already in use.
          Can be used only with ``--validate-config``
      * ``--print`` | ``-p`` -- used to print out local configuration (incl. environment configuration overrides).
          Can be used only with ``--validate-config``

    .. note::
        If running with ``--generate-config``, ``--generate-sample-config`` or ``--validate-flag`` will exit
        after generating or validating configuration.

    :returns: parsed arguments, if not running with ``--validate-config`` flag.
    
patroni/__main__.py