Skip to content

Commit

Permalink
ogrinfo: use GDALArgumentParser
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 13, 2024
1 parent 763c9fe commit 01c1099
Show file tree
Hide file tree
Showing 3 changed files with 367 additions and 274 deletions.
2 changes: 2 additions & 0 deletions apps/gdal_utils_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ struct GDALNearblackOptionsForBinary

std::string CPL_DLL GDALNearblackGetParserUsage();

std::string CPL_DLL GDALVectorInfoGetParserUsage();

#endif /* #ifndef DOXYGEN_SKIP */

#endif /* GDAL_UTILS_PRIV_H_INCLUDED */
50 changes: 4 additions & 46 deletions apps/ogrinfo_bin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,10 @@
/* Usage() */
/************************************************************************/

static void Usage(bool bIsError, const char *pszErrorMsg = nullptr)
static void Usage()
{
fprintf(bIsError ? stderr : stdout,
"Usage: ogrinfo [--help] [--help-general]\n"
" [-if <driver_name>] [-json] [-ro] [-q] [-where "
"<restricted_where>|@f<ilename>]\n"
" [-spat <xmin> <ymin> <xmax> <ymax>] [-geomfield "
"<field>] "
"[-fid <fid>]\n"
" [-sql <statement>|@<filename>] [-dialect "
"<sql_dialect>] "
"[-al] [-rl]\n"
" [-so|-features] [-fields={YES|NO}]]\n"
" [-geom={YES|NO|SUMMARY|WKT|ISO_WKT}] "
"[-oo <NAME>=<VALUE>]...\n"
" [-nomd] [-listmdd] [-mdd {<domain>|all}]...\n"
" [-nocount] [-nogeomtype] "
"[[-noextent] | [-extent3D]]\n"
" [-wkt_format WKT1|WKT2|<other_values>]\n"
" [-fielddomain <name>]\n"
" <datasource_name> [<layer> [<layer> ...]]\n");

if (pszErrorMsg != nullptr)
fprintf(stderr, "\nFAILURE: %s\n", pszErrorMsg);

exit(bIsError ? 1 : 0);
fprintf(stderr, "%s\n", GDALVectorInfoGetParserUsage().c_str());
exit(1);
}

/************************************************************************/
Expand All @@ -87,33 +65,13 @@ MAIN_START(argc, argv)
if (argc < 1)
exit(-argc);

for (int i = 0; argv != nullptr && argv[i] != nullptr; i++)
{
if (EQUAL(argv[i], "--utility_version"))
{
printf("%s was compiled against GDAL %s and is running against "
"GDAL %s\n",
argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME"));
CSLDestroy(argv);
return 0;
}
else if (EQUAL(argv[i], "--help"))
{
Usage(false);
}
}
argv = CSLAddString(argv, "-stdout");

auto psOptionsForBinary =
std::make_unique<GDALVectorInfoOptionsForBinary>();

GDALVectorInfoOptions *psOptions =
GDALVectorInfoOptionsNew(argv + 1, psOptionsForBinary.get());
if (psOptions == nullptr)
Usage(true);

if (psOptionsForBinary->osFilename.empty())
Usage(true, "No datasource specified.");
Usage();

/* -------------------------------------------------------------------- */
/* Open dataset. */
Expand Down
Loading

0 comments on commit 01c1099

Please sign in to comment.