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