Skip to content

Commit

Permalink
feat(entrypoints): add pretty print option (#590)
Browse files Browse the repository at this point in the history
Allow to pretty print the list of entrypoints if the flag `--pretty`
passed
  • Loading branch information
maksadbek authored Aug 23, 2024
1 parent e059024 commit 50e3fb2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
22 changes: 20 additions & 2 deletions src/Commands/GetEntryPoints.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import 'reflect-metadata';
import { Logger, logger } from '../Utils';
import { GetEntryPoints } from './GetEntryPoints';
import { EntryPoints } from '../EntryPoint';
import { mock, reset, spy, instance, when, anything, verify } from 'ts-mockito';
import {
mock,
reset,
spy,
instance,
when,
anything,
verify,
objectContaining
} from 'ts-mockito';
import { container } from 'tsyringe';
import { Arguments } from 'yargs';

Expand Down Expand Up @@ -34,14 +43,23 @@ describe('GetEntryPoints', () => {
it('should correctly pass config from args', async () => {
const args = {
project: '1',
limit: 10,
verbose: true,
pretty: true,
connectivity: ['connected', 'ok'],
status: ['open', 'closed', 'failed'],
_: [],
$0: ''
} as Arguments;

when(processSpy.exit(anything())).thenReturn(undefined);
when(
mockedEntryPoints.entrypoints({ projectId: '1', limit: 10 })
mockedEntryPoints.entrypoints(
objectContaining({
projectId: '1',
limit: 10
})
)
).thenResolve([
{
id: '1',
Expand Down
25 changes: 14 additions & 11 deletions src/Commands/GetEntryPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export class GetEntryPoints implements CommandModule {
describe: 'Limit the number of entrypoints',
default: 10
})
.option('pretty', {
describe: 'Pretty print the output',
boolean: true,
default: false
})
.option('connectivity', {
describe: 'Filter by connectivity',
array: true,
Expand Down Expand Up @@ -70,20 +75,18 @@ export class GetEntryPoints implements CommandModule {
status: args.status as string[]
});

if (args.verbose) {
// eslint-disable-next-line no-console
console.log('%j', entryPoints);
} else {
// eslint-disable-next-line no-console
console.log(
'%j',
entryPoints.map((entryPoint) => ({
const ep = args.verbose
? entryPoints
: entryPoints.map((entryPoint) => ({
id: entryPoint.id,
method: entryPoint.method,
url: entryPoint.url
}))
);
}
}));

// eslint-disable-next-line no-console
console.log(
args.pretty ? JSON.stringify(ep, null, 2) : JSON.stringify(ep)
);

process.exitCode = 0;
} catch (e) {
Expand Down

0 comments on commit 50e3fb2

Please sign in to comment.