Functions/GenXdev.Data.KeyValueStore/Remove-KeyValueStore.cs
|
// ################################################################################
// Part of PowerShell module : GenXdev.Data.KeyValueStore // Original cmdlet filename : Remove-KeyValueStore.cs // Original author : René Vaessen / GenXdev // Version : 3.28.2026 // ################################################################################ // Copyright (c) 2026 René Vaessen / GenXdev // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ################################################################################ using System.Management.Automation; namespace GenXdev.Data.KeyValueStore { [System.ComponentModel.Description(@" .SYNOPSIS Removes a local key-value store. .DESCRIPTION This function deletes a specified key-value store by physically removing its JSON file from disk. .EXAMPLE ```powershell Remove-KeyValueStore -StoreName ""MyStore"" ``` Remove a local key-value store named ""MyStore"". ")] [Cmdlet(VerbsCommon.Remove, "KeyValueStore")] [OutputType(typeof(void))] public class RemoveKeyValueStoreCommand : PSGenXdevCmdlet { /// <summary> /// Name of the store to delete /// </summary> [Parameter( Mandatory = true, Position = 0, HelpMessage = "Name of the store to delete")] [ValidateNotNullOrEmpty] public string StoreName { get; set; } /// <summary> /// Database path for key-value store data files /// </summary> [Parameter( Mandatory = false, HelpMessage = "Database path for key-value store data files")] public string DatabasePath { get; set; } private string basePath; /// <summary> /// Begin processing - determine base directory path /// </summary> protected override void BeginProcessing() { // Determine base directory path using provided path or default location if (string.IsNullOrWhiteSpace(DatabasePath)) { // Build default path to local application data folder basePath = GetGenXdevAppDataPath("KeyValueStore"); } else { // Use provided base path basePath = DatabasePath; } // Output verbose information about store directory location WriteVerbose($"Using KeyValueStore directory: {basePath}"); } /// <summary> /// Process record - remove the key-value store /// </summary> protected override void ProcessRecord() { // Verify user consent if (ShouldProcess(StoreName, "Delete store file")) { RemoveKeyValueStore(StoreName, DatabasePath); } } /// <summary> /// End processing - no cleanup needed /// </summary> protected override void EndProcessing() { } } } |