LCOV - code coverage report
Current view: top level - apps - gdalalg_dataset_delete.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 24 24 100.0 %
Date: 2026-07-09 08:35:43 Functions: 4 4 100.0 %

          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          47 : GDALDatasetDeleteAlgorithm::GDALDatasetDeleteAlgorithm()
      28          47 :     : GDALAlgorithm(NAME, DESCRIPTION, HELP_URL)
      29             : {
      30          47 :     AddProgressArg(/* hidden = */ true);
      31             : 
      32             :     {
      33             :         auto &arg =
      34          94 :             AddArg("filename", 0, _("File or directory name"), &m_filename)
      35          47 :                 .SetPositional()
      36          47 :                 .SetRequired();
      37          47 :         SetAutoCompleteFunctionForFilename(arg, 0);
      38             :     }
      39             : 
      40             :     {
      41             :         auto &arg =
      42          94 :             AddArg("format", 'f', _("Dataset format"), &m_format)
      43         141 :                 .AddMetadataItem(GAAMDI_REQUIRED_CAPABILITIES, {GDAL_DCAP_OPEN})
      44          47 :                 .SetCategory(GAAC_ADVANCED);
      45           2 :         arg.AddValidationAction([this, &arg]()
      46          49 :                                 { return ValidateFormat(arg, false, false); });
      47             :         arg.SetAutoCompleteFunction(
      48           1 :             [&arg](const std::string &)
      49             :             {
      50             :                 return GDALAlgorithm::FormatAutoCompleteFunction(arg, false,
      51           1 :                                                                  false);
      52          47 :             });
      53             :     }
      54          47 : }
      55             : 
      56             : /************************************************************************/
      57             : /*                GDALDatasetDeleteAlgorithm::RunImpl()                 */
      58             : /************************************************************************/
      59             : 
      60           3 : bool GDALDatasetDeleteAlgorithm::RunImpl(GDALProgressFunc, void *)
      61             : {
      62           3 :     GDALDriverH hDriver = nullptr;
      63           3 :     if (!m_format.empty())
      64           1 :         hDriver = GDALGetDriverByName(m_format.c_str());
      65             : 
      66           3 :     bool ret = true;
      67           6 :     for (const auto &datasetName : m_filename)
      68             :     {
      69           3 :         ret = ret && GDALDeleteDataset(hDriver, datasetName.c_str()) == CE_None;
      70             :     }
      71             : 
      72           3 :     return ret;
      73             : }
      74             : 
      75             : //! @endcond

Generated by: LCOV version 1.14