This commit is contained in:
48
src/commands/delete.ts
Normal file
48
src/commands/delete.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import inquirer from 'inquirer';
|
||||||
|
import { fileUtils } from '../utils/fileUtils';
|
||||||
|
|
||||||
|
interface DeleteOptions {
|
||||||
|
name: string;
|
||||||
|
force?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteLayout(options: DeleteOptions): Promise<void> {
|
||||||
|
await fileUtils.initialize();
|
||||||
|
|
||||||
|
let layoutName = options.name;
|
||||||
|
if (!layoutName) {
|
||||||
|
const layouts = await fileUtils.listLayouts();
|
||||||
|
if (layouts.length === 0) {
|
||||||
|
throw new Error('No layouts found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { selectedLayout } = await inquirer.prompt([
|
||||||
|
{
|
||||||
|
type: 'list',
|
||||||
|
name: 'selectedLayout',
|
||||||
|
message: 'Select a layout to delete:',
|
||||||
|
choices: layouts,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
layoutName = selectedLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.force) {
|
||||||
|
const { confirm } = await inquirer.prompt([
|
||||||
|
{
|
||||||
|
type: 'confirm',
|
||||||
|
name: 'confirm',
|
||||||
|
message: `Delete layout "${layoutName}"?`,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!confirm) {
|
||||||
|
console.log('Deletion cancelled.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await fileUtils.deleteLayout(layoutName);
|
||||||
|
console.log(`Layout deleted: ${layoutName}`);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user