Skip to content

Commit

Permalink
🐛 Stats wasn't working entirely like it should have
Browse files Browse the repository at this point in the history
  • Loading branch information
segersniels committed Mar 9, 2020
1 parent 1c59113 commit ee5869d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const run = async () => {

// Ugly repetitive code since pkg doesn't work well with dynamic importing
switch (command) {
case 'stats':
await new (await import('commands/stats')).default().run();
break;
case 'ssh':
await new (await import('commands/ssh')).default().run();
break;
Expand Down
2 changes: 1 addition & 1 deletion metadata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const metadata: Commands = {
description: 'See the stats of a container',
question: 'Which containers would you like to see that stats of?',
error: 'no containers available',
flags: [['p', 'prompt'], ['no-stream'], ['no-trunc']],
flags: [['p', 'prompt']],
type: CommandAlias.RUNNING_CONTAINERS,
allowFuzzySearching: true,
},
Expand Down
7 changes: 5 additions & 2 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ interface Internal {
@traceFunction()
export class Command {
private command: string;
private allowedFlags: string[];
private metadata: CommandType;
public metadata: CommandType;
public allowedFlags: string[];
public internal: Internal;
public mocking: boolean;
public config: Config;
Expand Down Expand Up @@ -295,6 +295,9 @@ export class Command {
}

public spawn(command: string, args: string[]) {
// Filter out all falsy arguments
args = args.filter(arg => arg);

return this.mocking
? parseOutput(args)
: spawnSync(command, args, { stdio: 'inherit' });
Expand Down
30 changes: 30 additions & 0 deletions src/commands/stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Command, MockingConfig } from './index';
import { traceFunction } from 'helpers/util';

@traceFunction()
export default class Stats extends Command {
constructor(config?: MockingConfig) {
super('stats', config);
}

public async run() {
await this.check();

if (this.flags.includes('--all')) {
return this.spawn('docker', ['stats', '--all']);
}

if (
this.allowedFlags.includes('prompt') &&
(this.flags.includes('-p') || this.flags.includes('--prompt'))
) {
await this.determine();
// Filter out the prompt flag for further execution
this.flags = this.flags.filter(
flag => !['--prompt', '-p'].includes(flag),
);
}

return this.execute();
}
}

0 comments on commit ee5869d

Please sign in to comment.