Skip to content

Commit

Permalink
add gitops.flux.checkPrereq. command and run it on ext. init (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomFractals committed Aug 31, 2021
1 parent 83b8ea8 commit 94c2829
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"activationEvents": [
"onCommand:gitops.kubectl.version",
"onCommand:gitops.flux.checkPrerequisites",
"onView:gitops.views.clusters",
"onView:gitops.views.sources",
"onView:gitops.views.deployments",
Expand All @@ -45,6 +46,11 @@
"command": "gitops.kubectl.version",
"title": "Kubectl Version",
"category": "GitOps"
},
{
"command": "gitops.flux.checkPrerequisites",
"title": "Flux Check Prerequisites",
"category": "GitOps"
}
],
"viewsContainers": {
Expand Down
15 changes: 15 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export enum KubectlCommands {
Version = 'gitops.kubectl.version'
}

/**
* Flux commands.
*/
export enum FluxCommands {
CheckPrerequisites = 'gitops.flux.checkPrerequisites'
}

let _context: ExtensionContext;

/**
Expand All @@ -31,6 +38,7 @@ let _context: ExtensionContext;
export function registerCommands(context: ExtensionContext) {
_context = context;
registerCommand(KubectlCommands.Version, showKubectlVersion);
registerCommand(FluxCommands.CheckPrerequisites, checkFluxPrerequisites);
}

/**
Expand All @@ -52,3 +60,10 @@ function registerCommand(commandName: string, callback: (...args: any[]) => any,
async function showKubectlVersion() {
runTerminalCommand(_context, 'kubectl', 'version');
}

/**
* Runs Flux check --pre command in gitops terminal.
*/
async function checkFluxPrerequisites() {
runTerminalCommand(_context, 'flux', 'check --pre');
}
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
commands,
window
} from 'vscode';
import { registerCommands, KubectlCommands } from './commands';
import { registerCommands, FluxCommands, KubectlCommands } from './commands';
import { ClusterTreeViewDataProvider } from './views/clusterTreeViewDataProvider';
import { DeploymentTreeViewDataProvider } from './views/deploymentTreeViewDataProvider';
import { LinkTreeViewDataProvider } from './views/linkTreeViewDataProvider';
Expand Down Expand Up @@ -42,6 +42,9 @@ export function activate(context: ExtensionContext) {

// show kubectl version in gitops terminal
commands.executeCommand(KubectlCommands.Version);

// run Flux prerequisites check
commands.executeCommand(FluxCommands.CheckPrerequisites);
}

export function deactivate() {}
8 changes: 3 additions & 5 deletions src/gitOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let _currentDirectory: string | undefined;
let _disposable: Disposable | undefined;

/**
* Gets gitops treminal instance
* Gets gitops treminal instance.
* @param context VScode extension context.
* @param workingDirectory Optional working directory path to cd to.
* @returns
Expand Down Expand Up @@ -46,15 +46,13 @@ function getTerminal(context: ExtensionContext, workingDirectory?: string): Term
* @param context VSCode extension context.
* @param command Command name.
* @param args Command arguments.
* @param workingDirectory Optional working directory.
* @param workingDirectory Optional working directory path to cd to.
*/
export function runTerminalCommand(
context: ExtensionContext,
command: string,
args: string,
workingDirectory?: string,
): void {

workingDirectory?: string): void {
const terminal = getTerminal(context, workingDirectory);
terminal.show(true);
terminal.sendText(`${command} ${args}`, true); // add new line
Expand Down

0 comments on commit 94c2829

Please sign in to comment.