diff --git a/src/crc-delete.ts b/src/crc-delete.ts index 7bb487b..19c252e 100644 --- a/src/crc-delete.ts +++ b/src/crc-delete.ts @@ -32,32 +32,36 @@ export function registerDeleteCommand(extensionContext: extensionApi.ExtensionCo ); extensionContext.subscriptions.push( - extensionApi.commands.registerCommand('crc.delete', async () => { - if (crcStatus.status.CrcStatus === 'No Cluster') { - await extensionApi.window.showNotification({ - silent: false, - title: productName, - body: 'Machine does not exist. Use "start" to create it', - }); - return; - } - const confirmation = await extensionApi.window.showInformationMessage( - 'Do you want to delete the instance?', - 'Yes', - 'No', - ); - if (confirmation === 'Yes') { - try { - await commander.delete(); - await extensionApi.window.showNotification({ - silent: false, - title: productName, - body: 'Deleted the instance.', - }); - } catch (err) { - console.error(err); - } - } + extensionApi.commands.registerCommand('crc.delete', () => { + return deleteCrc(); }), ); } + +export async function deleteCrc(): Promise { + if (crcStatus.status.CrcStatus === 'No Cluster') { + await extensionApi.window.showNotification({ + silent: false, + title: productName, + body: 'Machine does not exist. Use "start" to create it', + }); + return; + } + const confirmation = await extensionApi.window.showInformationMessage( + 'Do you want to delete the instance?', + 'Yes', + 'No', + ); + if (confirmation === 'Yes') { + try { + await commander.delete(); + await extensionApi.window.showNotification({ + silent: false, + title: productName, + body: 'Deleted the instance.', + }); + } catch (err) { + console.error(err); + } + } +} diff --git a/src/crc-stop.ts b/src/crc-stop.ts new file mode 100644 index 0000000..ab11aa2 --- /dev/null +++ b/src/crc-stop.ts @@ -0,0 +1,30 @@ +/********************************************************************** + * Copyright (C) 2023 Red Hat, Inc. + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + ***********************************************************************/ + +import { commander } from './daemon-commander'; +import { crcLogProvider } from './log-provider'; + +export async function stopCrc(): Promise { + console.log('extension:crc: receive the call stop'); + try { + await commander.stop(); + crcLogProvider.stopSendingLogs(); + } catch (err) { + console.error(err); + } +} diff --git a/src/extension.ts b/src/extension.ts index f72fbd1..7e99a63 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,8 +21,6 @@ import * as path from 'node:path'; import * as os from 'node:os'; import * as fs from 'node:fs'; import type { Status } from './daemon-commander'; -import { commander } from './daemon-commander'; -import { crcLogProvider } from './log-provider'; import { isWindows, productName, providerId } from './util'; import { daemonStart, daemonStop, getCrcVersion } from './crc-cli'; import { getCrcDetectionChecks } from './detection-checks'; @@ -31,8 +29,9 @@ import { CrcInstall } from './install/crc-install'; import { crcStatus } from './crc-status'; import { startCrc } from './crc-start'; import { isNeedSetup, needSetup } from './crc-setup'; -import { registerDeleteCommand } from './crc-delete'; +import { deleteCrc, registerDeleteCommand } from './crc-delete'; import { syncPreferences } from './preferences'; +import { stopCrc } from './crc-stop'; export async function activate(extensionContext: extensionApi.ExtensionContext): Promise { const crcInstaller = new CrcInstall(); @@ -161,6 +160,17 @@ async function registerOpenShiftLocalCluster( apiURL, }, status, + lifecycle: { + delete: () => { + return deleteCrc(); + }, + start: ctx => { + return startCrc(ctx.log); + }, + stop: () => { + return stopCrc(); + }, + }, }; const disposable = provider.registerKubernetesProviderConnection(kubernetesProviderConnection); @@ -203,13 +213,3 @@ function presetChanged(provider: extensionApi.Provider, extensionContext: extens registerOpenShiftLocalCluster(provider, extensionContext); } } - -async function stopCrc(): Promise { - console.log('extension:crc: receive the call stop'); - try { - await commander.stop(); - crcLogProvider.stopSendingLogs(); - } catch (err) { - console.error(err); - } -}