mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-02-01 00:24:31 +01:00
Track networking commands
This commit is contained in:
@@ -25,7 +25,7 @@ log.debug("started");
|
||||
|
||||
function executeStartupCommands() {
|
||||
log.debug("Executing startup commands", appData.startupCommands);
|
||||
appData.startupCommands.forEach(cmd.execute.bind(cmd));
|
||||
appData.startupCommands.forEach(c => cmd.execute(c, {doNotTrack: true}));
|
||||
}
|
||||
|
||||
function initializeModules() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import AppState from '../shell/AppState';
|
||||
import { CmdShell, CommandInput } from '../shell/cmd';
|
||||
import { CmdShell, CommandInput, CommandOptions } from '../shell/cmd';
|
||||
import ErrorResultView from '../shell/components/ErrorResultView';
|
||||
import IpAddressView from './components/IpAddressView';
|
||||
import ipAddressParser, {ParsingError, ParsedIpObject} from './ip-parser';
|
||||
@@ -8,6 +8,7 @@ import { IpAddress, IpAddressWithSubnetMask, SubnetCommand } from "./models";
|
||||
import log from 'loglevel';
|
||||
import SubnetView from './components/SubnetView';
|
||||
import { createSubnetMaskIp } from './subnet-utils';
|
||||
import {sendAnalyticsEvent} from '../shell/analytics';
|
||||
|
||||
const networkingAppModule = {
|
||||
setup: function(appState: AppState, cmd: CmdShell) {
|
||||
@@ -28,6 +29,7 @@ const networkingAppModule = {
|
||||
|
||||
if(result instanceof SubnetCommand) {
|
||||
appState.addCommandResult(c.input, <SubnetView subnet={result} />);
|
||||
trackCommand('SubnetCommand', c.options);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,6 +45,8 @@ const networkingAppModule = {
|
||||
ipAddresses.push(r);
|
||||
}
|
||||
});
|
||||
|
||||
trackCommand("IpAddressesInput", c.options);
|
||||
|
||||
appState.addCommandResult(c.input, <IpAddressView ipAddresses={ipAddresses} />);
|
||||
}
|
||||
@@ -52,4 +56,13 @@ const networkingAppModule = {
|
||||
}
|
||||
}
|
||||
|
||||
function trackCommand(action: string, ops: CommandOptions) {
|
||||
if(ops.doNotTrack !== true) {
|
||||
sendAnalyticsEvent({
|
||||
eventCategory: "NetworkingCommand",
|
||||
eventAction: action
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default networkingAppModule;
|
||||
@@ -3,11 +3,20 @@ import log from 'loglevel';
|
||||
|
||||
export type CommandInput = {
|
||||
input: string;
|
||||
options: CommandOptions
|
||||
}
|
||||
|
||||
export type CommandOptions = {
|
||||
doNotTrack: boolean;
|
||||
}
|
||||
|
||||
type HandleFunction = (input: CommandInput) => void;
|
||||
type InputErrorHandler = (input:string, error: Error) => void;
|
||||
|
||||
const DEFUALT_COMMAND_OPTIONS : CommandOptions = {
|
||||
doNotTrack: false
|
||||
};
|
||||
|
||||
export interface ICommandHandler {
|
||||
canHandle (input:string) : boolean;
|
||||
handle: HandleFunction;
|
||||
@@ -23,19 +32,21 @@ export class CmdShell {
|
||||
this.errorHandler = null;
|
||||
};
|
||||
|
||||
execute (rawInput: string) {
|
||||
execute (rawInput: string, ops?: CommandOptions ) {
|
||||
|
||||
log.debug(`Executing command: ${rawInput}`)
|
||||
log.debug(`Executing command: ${rawInput}`);
|
||||
|
||||
ops = ops || Object.assign({}, DEFUALT_COMMAND_OPTIONS);
|
||||
|
||||
var input = rawInput.trim().toLowerCase();
|
||||
var handler = this.findHandler(input);
|
||||
|
||||
if(handler != null) {
|
||||
if(this.debugMode) {
|
||||
this.invokeHandler(input, handler);
|
||||
this.invokeHandler(input, handler, ops);
|
||||
} else {
|
||||
try {
|
||||
this.invokeHandler(input, handler);
|
||||
this.invokeHandler(input, handler, ops);
|
||||
} catch (e) {
|
||||
this.handleError(input, e);
|
||||
}
|
||||
@@ -87,9 +98,9 @@ export class CmdShell {
|
||||
return this.handlers.filter(h => h.canHandle(input))[0];
|
||||
};
|
||||
|
||||
invokeHandler (input : string, handler : ICommandHandler) {
|
||||
invokeHandler (input : string, handler : ICommandHandler, options: CommandOptions) {
|
||||
|
||||
var cmdResult = handler.handle({ input: input});
|
||||
var cmdResult = handler.handle({ input: input, options });
|
||||
if(cmdResult != null) {
|
||||
log.debug(cmdResult);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user