1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/******************************************************************************
*
* Project: GDAL
* Purpose: gdal "dataset delete" subcommand
* Author: Even Rouault <even dot rouault at spatialys.com>
*
******************************************************************************
* Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
*
* SPDX-License-Identifier: MIT
****************************************************************************/
#include "gdalalg_dataset_delete.h"
#include "gdal.h"
//! @cond Doxygen_Suppress
#ifndef _
#define _(x) (x)
#endif
/************************************************************************/
/* GDALDatasetDeleteAlgorithm() */
/************************************************************************/
GDALDatasetDeleteAlgorithm::GDALDatasetDeleteAlgorithm()
: GDALAlgorithm(NAME, DESCRIPTION, HELP_URL)
{
{
auto &arg =
AddArg("filename", 0, _("File or directory name"), &m_filename)
.SetPositional()
.SetRequired();
SetAutoCompleteFunctionForFilename(arg, 0);
}
{
auto &arg =
AddArg("format", 'f', _("Dataset format"), &m_format)
.AddMetadataItem(GAAMDI_REQUIRED_CAPABILITIES, {GDAL_DCAP_OPEN})
.SetCategory(GAAC_ADVANCED);
arg.AddValidationAction([this, &arg]()
{ return ValidateFormat(arg, false, false); });
arg.SetAutoCompleteFunction(
[&arg](const std::string &) {
return GDALAlgorithm::FormatAutoCompleteFunction(arg, false,
false);
});
}
}
/************************************************************************/
/* GDALDatasetDeleteAlgorithm::RunImpl() */
/************************************************************************/
bool GDALDatasetDeleteAlgorithm::RunImpl(GDALProgressFunc, void *)
{
GDALDriverH hDriver = nullptr;
if (!m_format.empty())
hDriver = GDALGetDriverByName(m_format.c_str());
bool ret = true;
for (const auto &datasetName : m_filename)
{
ret = ret && GDALDeleteDataset(hDriver, datasetName.c_str()) == CE_None;
}
return ret;
}
//! @endcond
|