GDAL

Public Member Functions | List of all members
GDALArgumentParser Class Reference

Parse command-line arguments for GDAL utilities. More...

`#include <gdalargumentparser.h>`

Inheritance diagram for GDALArgumentParser:

## Public Member Functions
| GDALArgumentParser (const std::string &program_name, bool bForBinary)
| Constructor.
std::string | usage () const
| Return usage message.
void | add_extra_usage_hint (const std::string &osExtraUsageHint)
| Adds an extra usage hint.
void | display_error_and_usage (const std::exception &err)
| Format an exception as an error message and display the program usage.
Argument & | add_quiet_argument (bool *pVar)
| Add -q/--quiet argument, and store its value in *pVar (if pVar not null)
Argument & | add_input_format_argument (CPLStringList *pvar)
| Add "-if format_name" argument for input format, and store its value into *pvar.
Argument & | add_output_format_argument (std::string &var)
| Add "-of format_name" argument for output format, and store its value into var.
Argument & | add_creation_options_argument (CPLStringList &var)
| Add "-co KEY=VALUE" argument for creation options, and store its value into var.
Argument & | add_metadata_item_options_argument (CPLStringList &var)
| Add "-mo KEY=VALUE" argument for metadata item options, and store its value into var.
Argument & | add_open_options_argument (CPLStringList &var)
| Add "-oo KEY=VALUE" argument for open options, and store its value into var.
Argument & | add_open_options_argument (CPLStringList *pvar)
| Add "-oo KEY=VALUE" argument for open options, and store its value into *pvar.
Argument & | add_output_type_argument (GDALDataType &eDT)
| Add "-ot data_type" argument for output type, and store its value into eDT.
Argument & | add_layer_creation_options_argument (CPLStringList &var)
| Add "-lco NAME=VALUE" argument for layer creation options, and store its value into var.
Argument & | add_dataset_creation_options_argument (CPLStringList &var)
| Add "-dsco NAME=VALUE" argument for dataset creation options, and store its value into var.
void | parse_args_without_binary_name (CSLConstList papszArgs)
| Parse command line arguments, without the initial program name.
void | parse_args (const CPLStringList &aosArgs)
| Parse command line arguments, with the initial program name.
CPLStringList | get_non_positional_arguments (const CPLStringList &aosArgs)
| Return the non positional arguments.
Argument & | add_inverted_logic_flag (const std::string &name, bool *store_into=nullptr, const std::string &help="")
| Add an inverted logic (default true, false when set) flag.
GDALArgumentParser * | add_subparser (const std::string &description, bool bForBinary)
| Create and add a subparser to the argument parser, keeping ownership.
GDALArgumentParser * | get_subparser (const std::string &name)
| Get a subparser by name (case insensitive)
bool | is_used_globally (const std::string &name)
| Return true if the argument is used in the command line (also checking subparsers, if any)

## Detailed Description

Parse command-line arguments for GDAL utilities.

Add helpers over the standard argparse::ArgumentParser class

Since
  GDAL 3.9

## Member Function Documentation

## ◆ add_inverted_logic_flag()

Argument & GDALArgumentParser::add_inverted_logic_flag | ( | const std::string & | name,
|  | bool * | store_into = `nullptr`,
|  | const std::string & | help = `""`
| ) |  |

Add an inverted logic (default true, false when set) flag.

Parameters

  name | flag name
  store_into | optional pointer to a bool variable where to store the value
  help | optional help text

## ◆ add_subparser()

GDALArgumentParser * GDALArgumentParser::add_subparser | ( | const std::string & | description,
|  | bool | bForBinary
| ) |  |

Create and add a subparser to the argument parser, keeping ownership.

Parameters

  description | Subparser description
  bForBinary | True if the subparser is for a binary utility, false for a library

Returns
  A pointer to the created subparser

## ◆ get_subparser()

GDALArgumentParser * GDALArgumentParser::get_subparser | ( | const std::string & | name | ) |

Get a subparser by name (case insensitive)

Parameters

  name | Subparser name

Returns
  The subparser or nullptr if not found

## ◆ is_used_globally()

bool GDALArgumentParser::is_used_globally | ( | const std::string & | name | ) |

Return true if the argument is used in the command line (also checking subparsers, if any)

Parameters

  name | Argument name

Returns
  True if the argument is used, false if it is not used.

Note
  Opposite to the is_used() function this is case insensitive, also checks subparsers and never throws

The documentation for this class was generated from the following files:

- gdalargumentparser.h
- gdalargumentparser.cpp