LCOV - code coverage report
Current view: top level - apps - gdalalg_dataset_delete.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 23 23 100.0 %
Date: 2025-05-15 13:16:46 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           5 : GDALDatasetDeleteAlgorithm::GDALDatasetDeleteAlgorithm()
      28           5 :     : GDALAlgorithm(NAME, DESCRIPTION, HELP_URL)
      29             : {
      30             :     {
      31             :         auto &arg =
      32          10 :             AddArg("filename", 0, _("File or directory name"), &m_filename)
      33           5 :                 .SetPositional()
      34           5 :                 .SetRequired();
      35           5 :         SetAutoCompleteFunctionForFilename(arg, 0);
      36             :     }
      37             : 
      38             :     {
      39             :         auto &arg =
      40          10 :             AddArg("format", 'f', _("Dataset format"), &m_format)
      41          15 :                 .AddMetadataItem(GAAMDI_REQUIRED_CAPABILITIES, {GDAL_DCAP_OPEN})
      42           5 :                 .SetCategory(GAAC_ADVANCED);
      43           1 :         arg.AddValidationAction([this, &arg]()
      44           6 :                                 { return ValidateFormat(arg, false, false); });
      45             :         arg.SetAutoCompleteFunction(
      46           1 :             [&arg](const std::string &) {
      47             :                 return GDALAlgorithm::FormatAutoCompleteFunction(arg, false,
      48           1 :                                                                  false);
      49           5 :             });
      50             :     }
      51           5 : }
      52             : 
      53             : /************************************************************************/
      54             : /*                  GDALDatasetDeleteAlgorithm::RunImpl()               */
      55             : /************************************************************************/
      56             : 
      57           3 : bool GDALDatasetDeleteAlgorithm::RunImpl(GDALProgressFunc, void *)
      58             : {
      59           3 :     GDALDriverH hDriver = nullptr;
      60           3 :     if (!m_format.empty())
      61           1 :         hDriver = GDALGetDriverByName(m_format.c_str());
      62             : 
      63           3 :     bool ret = true;
      64           6 :     for (const auto &datasetName : m_filename)
      65             :     {
      66           3 :         ret = ret && GDALDeleteDataset(hDriver, datasetName.c_str()) == CE_None;
      67             :     }
      68             : 
      69           3 :     return ret;
      70             : }
      71             : 
      72             : //! @endcond

Generated by: LCOV version 1.14