Skip to content

Commit

Permalink
style: codacy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan committed Sep 23, 2019
1 parent e3907c2 commit 98d0a31
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 47 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"check-format": "prettier --ignore-path .eslintignore \"**/*.{js,ts}\" --list-different && npm run lint -- --quiet",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"debug": "node --nolazy --inspect-brk=9229 node_modules/jest/bin/jest.js -i",
"bump": "npm version prerelease --preid alpha -m \" build: :bookmark:%s bump\"",
"beta": "npm version prerelease --preid beta -m \"build: :bookmark: %s beta\"",
"release:alpha": "npm version prerelease --preid alpha -m \" build: :bookmark:%s alpha\"",
"release:beta": "npm version prerelease --preid beta -m \"build: :bookmark: %s beta\"",
"release:patch": "npm version patch -m \"build: :bookmark: %s patch\"",
"release:minor": "npm version minor -m \"build: :bookmark: %s minor\"",
"release:major": "npm version major -m \"build: :bookmark: %s major\"",
Expand Down
8 changes: 4 additions & 4 deletions src/lib/commandParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ const createCommand = (path: FlexiPath): Command => {

const content = requireContent(result);
return {
args,
description: content.description,
fullName: commandFullName(result),
helpName: content.helpname,
name: commandName(result),
fullname: commandFullName(result),
run: content.run,
helpname: content.helpname,
description: content.description,
args,
subCommands: result
.children()
.filter(x => isCommand(x) && x.name !== "index")
Expand Down
9 changes: 6 additions & 3 deletions src/lib/commands/firewall/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
import { CommandDeclaration } from "../../../types";
import ssh from "../../ssh";

const firewall = (args: string[]): void => {
Expand All @@ -14,8 +15,10 @@ const firewall = (args: string[]): void => {
}
};

export default {
const declaration = (): CommandDeclaration => ({
run: firewall,
helpname: "firewall [args]",
helpName: "firewall [args]",
description: "Opens the Skynet firewall with (optional) arguments"
};
});

export default declaration;
8 changes: 6 additions & 2 deletions src/lib/commands/firewall/log/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env node
export default {
import { CommandDeclaration } from "../../../../types";

const declaration = (): CommandDeclaration => ({
description: "Copy or analyze firewall log"
};
});

export default declaration;
7 changes: 5 additions & 2 deletions src/lib/commands/firewall/log/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env node
import { CommandDeclaration } from "../../../../types";
import ssh from "../../../ssh";

const transfer = (): void => {
// TODO
ssh.execute("cat /tmp/mnt/USB/skynet/skynet.log");
};

export default {
const declaration = (): CommandDeclaration => ({
run: transfer,
description: "Transfers the firewall log"
};
});

export default declaration;
7 changes: 5 additions & 2 deletions src/lib/commands/info/commands.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env node
import { CommandDeclaration } from "../../../types";
import ssh from "../../ssh";

const commands = (): void => {
ssh.execute("ls -1 /usr/bin/ | grep -v '^d'");
};

export default {
const declaration = (): CommandDeclaration => ({
description: "Lists files in /usr/bin",
run: commands
};
});

export default declaration;
8 changes: 6 additions & 2 deletions src/lib/commands/info/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env node
export default {
import { CommandDeclaration } from "../../../types";

const declaration = (): CommandDeclaration => ({
description: "Shows router information"
};
});

export default declaration;
7 changes: 5 additions & 2 deletions src/lib/commands/info/uptime.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env node
import ssh from "../../ssh";
import { CommandDeclaration } from "../../../types";

const uptime = (): void => {
ssh.execute("uptime");
};

export default {
const declaration = (): CommandDeclaration => ({
description: "Display router uptime",
run: uptime
};
});

export default declaration;
13 changes: 8 additions & 5 deletions src/lib/commands/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env node
import ssh from "../ssh";
import { CommandDeclaration } from "../../types";

const terminal = (args: string[]): void => {
ssh.executeInTerminal(args);
};

export default {
run: terminal,
helpname: "terminal [args]",
const declaration = (): CommandDeclaration => ({
description:
"Opens an ssh connection to the router and executes the args (optional)"
};
"Opens an ssh connection to the router and executes the args (optional)",
helpName: "terminal [args]",
run: terminal
});

export default declaration;
4 changes: 2 additions & 2 deletions src/lib/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const help = (command?: Command | null): void => {
const guardCheckedCommand = command as Command;
const commandName = isRootHelp
? ""
: chalk.bold(` ${guardCheckedCommand.fullname}`);
: chalk.bold(` ${guardCheckedCommand.fullName}`);
logger.debug(undefined, {
functionName: "help",
meta: { isRootHelp, commandName }
Expand All @@ -32,7 +32,7 @@ const help = (command?: Command | null): void => {
: guardCheckedCommand.subCommands || [command];

commands.forEach(x =>
lines.push(toColumns([` ${x.helpname || x.name}`, x.description]))
lines.push(toColumns([` ${x.helpName || x.name}`, x.description]))
);

if (isRootHelp || commands.filter(x => x.subCommands.length > 0)) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const levelMinWidth = 9;
const categoryMinWidth = 40;

const rootLogger = createLogger({
level: isDebug ? "debug" : "info",
format: combine(
format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
align(),
Expand All @@ -48,6 +47,7 @@ const rootLogger = createLogger({
}),
colorize({ all: true })
),
level: isDebug ? "debug" : "info",
transports: [
new transports.Console(),
new transports.File({ filename: "combined.log", handleExceptions: true })
Expand Down
10 changes: 5 additions & 5 deletions src/types/Command.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node
export interface Command {
export default interface Command {
args?: string[];
description: string;
fullName: string;
helpName: string;
name: string;
fullname: string;
run: any;
helpname: string;
description: string;
args?: string[];
subCommands: Command[];
}
5 changes: 5 additions & 0 deletions src/types/CommandDeclaration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default interface CommandDeclaration {
description?: string;
helpName?: string;
run?: any;
}
6 changes: 3 additions & 3 deletions src/types/CommandParser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node
import { Command } from ".";

export interface CommandParser {
export default interface CommandParser {
isHelp: boolean;
isDebug: boolean;
all(): Command[];
find(): Command | null;
all: () => Command[];
find: () => Command | null;
stripOptions: () => string[];
}
2 changes: 1 addition & 1 deletion src/types/ConfigCreationData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SshConfig } from ".";

export interface ConfigCreationData extends SshConfig {
export default interface ConfigCreationData extends SshConfig {
passPhrase: string;
createKeyFile: boolean;
addKeyToAgent: boolean;
Expand Down
4 changes: 3 additions & 1 deletion src/types/PromptBody.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import promptly from "promptly";

export type PromptBody = (message: string, opts: promptly.Options) => any;
type PromptBody = (message: string, opts: promptly.Options) => any;

export default PromptBody;
4 changes: 3 additions & 1 deletion src/types/PromptType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export enum PromptType {
enum PromptType {
Text,
Password,
Confirm
}

export default PromptType;
2 changes: 1 addition & 1 deletion src/types/SshConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface SshConfig {
export default interface SshConfig {
host: string;
userName: string;
privateKey: string;
Expand Down
13 changes: 7 additions & 6 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./ConfigCreationData";
export * from "./Command";
export * from "./CommandParser";
export * from "./PromptType";
export * from "./PromptBody";
export * from "./SshConfig";
export { default as Command } from "./Command";
export { default as CommandDeclaration } from "./CommandDeclaration";
export { default as CommandParser } from "./CommandParser";
export { default as ConfigCreationData } from "./ConfigCreationData";
export { default as PromptType } from "./PromptType";
export { default as PromptBody } from "./PromptBody";
export { default as SshConfig } from "./SshConfig";
4 changes: 2 additions & 2 deletions test/commandParser.find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("commandParser", () => {
const terminalCommand = result as Command;

expect(terminalCommand.name).toBe(terminal);
expect(terminalCommand.fullname).toBe(terminal);
expect(terminalCommand.fullName).toBe(terminal);
expect(terminalCommand.subCommands).toBeEmpty();
});

Expand All @@ -50,7 +50,7 @@ describe("commandParser", () => {
const uptimeCommand = result as Command;

expect(uptimeCommand.name).toBe(level2);
expect(uptimeCommand.fullname).toBe(`${level1} ${level2}`);
expect(uptimeCommand.fullName).toBe(`${level1} ${level2}`);
});
});
});

0 comments on commit 98d0a31

Please sign in to comment.