Skip to content

Commit 77821a0

Browse files
committed
reformat
1 parent b0c4ad1 commit 77821a0

19 files changed

Lines changed: 508 additions & 466 deletions

src/app.module.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import {Module} from '@nestjs/common';
2-
import {ApiCommand} from './commands/api/ApiCommand';
3-
import {VersionCommand} from "./commands/VersionCommand";
4-
import {WalletCommand} from "./commands/wallet/WalletCommand";
5-
import {ConfigModule} from "@nestjs/config";
6-
import {ConfirmQuestion} from "./questions/ConfirmQuestion";
7-
import {ContentExporter} from "./services/ContentExporter";
8-
import {MagicPipConvert} from "./questions/MagicPipConvert";
1+
import { Module } from '@nestjs/common';
2+
import { ApiCommand } from './commands/api/ApiCommand';
3+
import { VersionCommand } from './commands/VersionCommand';
4+
import { WalletCommand } from './commands/wallet/WalletCommand';
5+
import { ConfigModule } from '@nestjs/config';
6+
import { ConfirmQuestion } from './questions/ConfirmQuestion';
7+
import { ContentExporter } from './services/ContentExporter';
8+
import { MagicPipConvert } from './questions/MagicPipConvert';
99

1010
@Module({
11-
imports: [ConfigModule.forRoot()],
12-
controllers: [],
13-
providers: [
14-
VersionCommand,
15-
...ApiCommand.registerWithSubCommands(),
16-
...WalletCommand.registerWithSubCommands(),
17-
ConfirmQuestion,
18-
ContentExporter,
19-
MagicPipConvert,
20-
],
11+
imports: [ConfigModule.forRoot()],
12+
controllers: [],
13+
providers: [
14+
VersionCommand,
15+
...ApiCommand.registerWithSubCommands(),
16+
...WalletCommand.registerWithSubCommands(),
17+
ConfirmQuestion,
18+
ContentExporter,
19+
MagicPipConvert,
20+
],
2121
})
22-
export class AppModule {
23-
}
22+
export class AppModule {}

src/commands/VersionCommand.spec.ts

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
import {VersionCommand} from "./VersionCommand";
2-
import {CommandTestFactory} from "nest-commander-testing";
3-
import {TestingModule} from "@nestjs/testing";
1+
import { VersionCommand } from './VersionCommand';
2+
import { CommandTestFactory } from 'nest-commander-testing';
3+
import { TestingModule } from '@nestjs/testing';
44
import * as childProcess from 'child_process';
5-
import {AppModule} from "../app.module";
65

76
describe('VersionCommand', () => {
8-
let commandInstance: TestingModule;
9-
// let command: VersionCommand;
10-
let spawnSpy: jest.SpyInstance;
7+
let commandInstance: TestingModule;
8+
// let command: VersionCommand;
9+
let spawnSpy: jest.SpyInstance;
1110

12-
beforeAll(async () => {
13-
commandInstance = await CommandTestFactory.createTestingCommand({
14-
imports: [],
15-
providers: [VersionCommand],
16-
}).compile();
17-
// command = commandInstance.get(VersionCommand);
18-
});
11+
beforeAll(async () => {
12+
commandInstance = await CommandTestFactory.createTestingCommand({
13+
imports: [],
14+
providers: [VersionCommand],
15+
}).compile();
16+
// command = commandInstance.get(VersionCommand);
17+
});
1918

20-
beforeEach(() => {
21-
// Мокаем spawn и сохраняем spy для проверок
22-
/* spawnSpy = jest.spyOn(childProcess, 'spawn').mockImplementation(() => {
19+
beforeEach(() => {
20+
// Мокаем spawn и сохраняем spy для проверок
21+
/* spawnSpy = jest.spyOn(childProcess, 'spawn').mockImplementation(() => {
2322
return {
2423
on: jest.fn((event, callback) => {
2524
if (event === 'close') callback(0);
@@ -28,30 +27,30 @@ describe('VersionCommand', () => {
2827
stderr: { on: jest.fn() }
2928
} as unknown as childProcess.ChildProcess;
3029
});*/
31-
});
30+
});
3231

33-
afterEach(() => {
34-
jest.restoreAllMocks();
35-
});
32+
afterEach(() => {
33+
jest.restoreAllMocks();
34+
});
3635

37-
it('should be defined', async () => {
38-
spawnSpy = jest.spyOn(childProcess, 'spawn');
39-
await CommandTestFactory.run(commandInstance, ['version'])
40-
// Проверяем, что spawn был вызван
41-
// expect(spawnSpy).toHaveBeenCalled();
36+
it('should be defined', async () => {
37+
spawnSpy = jest.spyOn(childProcess, 'spawn');
38+
await CommandTestFactory.run(commandInstance, ['version']);
39+
// Проверяем, что spawn был вызван
40+
// expect(spawnSpy).toHaveBeenCalled();
4241

43-
// Получаем все вызовы spawn
44-
const spawnCalls = spawnSpy.mock.calls;
45-
console.log('Все вызовы spawn:', spawnCalls);
42+
// Получаем все вызовы spawn
43+
const spawnCalls = spawnSpy.mock.calls;
44+
console.log('Все вызовы spawn:', spawnCalls);
4645

47-
// Проверяем первый вызов
48-
const firstCall = spawnSpy.mock.calls[0];
49-
console.log('Первый вызов spawn:', firstCall);
50-
// expect(spawnSpy).toBeCalledWith('minter-cli version 0.1.0');
51-
// expect(spawnSpy).toHaveBeenCalledWith('minter-cli version 0.1.0');
52-
});
46+
// Проверяем первый вызов
47+
const firstCall = spawnSpy.mock.calls[0];
48+
console.log('Первый вызов spawn:', firstCall);
49+
// expect(spawnSpy).toBeCalledWith('minter-cli version 0.1.0');
50+
// expect(spawnSpy).toHaveBeenCalledWith('minter-cli version 0.1.0');
51+
});
5352

54-
/* it('should be defined2', async () => {
53+
/* it('should be defined2', async () => {
5554
5655
command.run([], []).then(result => {
5756
console.info(result);

src/commands/VersionCommand.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import {Command, CommandRunner} from 'nest-commander';
2-
import {readFile} from 'fs/promises';
1+
import { Command, CommandRunner } from 'nest-commander';
2+
import { readFile } from 'fs/promises';
33

44
@Command({
5-
name: "version",
6-
description: 'version app'
5+
name: 'version',
6+
description: 'version app',
77
})
88
export class VersionCommand extends CommandRunner {
9-
async run(passedParams: string[], options?: Record<string, any>): Promise<void> {
10-
const version = await this.getVersion();
11-
// console.log(passedParams);
12-
console.log(`minter-cli version ${version}`);
13-
// process.stdout.write(`minter-cli version ${version}`);
14-
return Promise.resolve(undefined);
15-
}
9+
async run(
10+
passedParams: string[],
11+
options?: Record<string, any>,
12+
): Promise<void> {
13+
const version = await this.getVersion();
14+
// console.log(passedParams);
15+
console.log(`minter-cli version ${version}`);
16+
// process.stdout.write(`minter-cli version ${version}`);
17+
return Promise.resolve(undefined);
18+
}
1619

17-
/* @Option({
20+
/* @Option({
1821
flags: '--version [boolean]',
1922
description:
2023
' ',
@@ -24,8 +27,10 @@ export class VersionCommand extends CommandRunner {
2427
return JSON.parse(val);
2528
}*/
2629

27-
async getVersion(): Promise<string> {
28-
const packageJson = JSON.parse(await readFile(__dirname+'/../../package.json', 'utf-8'));
29-
return packageJson.version;
30-
}
30+
async getVersion(): Promise<string> {
31+
const packageJson = JSON.parse(
32+
await readFile(__dirname + '/../../package.json', 'utf-8'),
33+
);
34+
return packageJson.version;
35+
}
3136
}
Lines changed: 95 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,110 @@
1-
import {Option, CommandRunner, SubCommand} from 'nest-commander';
2-
import {MinterApiService} from '../../services/minter-api/minter-api.service';
3-
import {ContentExporter} from "../../services/ContentExporter";
1+
import { Option, CommandRunner, SubCommand } from 'nest-commander';
2+
import { MinterApiService } from '../../services/minter-api/minter-api.service';
3+
import { ContentExporter } from '../../services/ContentExporter';
44

55
@SubCommand({
6-
name: 'candidate',
7-
arguments: '<public_key>',
8-
argsDescription: {public_key: 'Public key'},
9-
description: 'Candidate returns candidate’s info by provided public key',
6+
name: 'candidate',
7+
arguments: '<public_key>',
8+
argsDescription: { public_key: 'Public key' },
9+
description: 'Candidate returns candidate’s info by provided public key',
1010
})
1111
export class CandidateCommand extends CommandRunner {
12-
private skip_pip2bip = false;
12+
private skip_pip2bip = false;
1313

14-
constructor(private contentExporter: ContentExporter) {
15-
super();
16-
}
14+
constructor(private contentExporter: ContentExporter) {
15+
super();
16+
}
1717

18-
async run(
19-
inputs: string[],
20-
options: {
21-
height?: number;
22-
not_show_stakes?: boolean;
23-
config: string;
24-
patch?: string;
25-
patches: boolean;
26-
pretty: boolean
27-
},
28-
): Promise<void> {
29-
// const {patch, config} = options;
30-
const candidate = inputs[0];
31-
const minterApi = new MinterApiService(options.config);
18+
async run(
19+
inputs: string[],
20+
options: {
21+
height?: number;
22+
not_show_stakes?: boolean;
23+
config: string;
24+
patch?: string;
25+
patches: boolean;
26+
pretty: boolean;
27+
},
28+
): Promise<void> {
29+
// const {patch, config} = options;
30+
const candidate = inputs[0];
31+
const minterApi = new MinterApiService(options.config);
3232

33-
minterApi.api().getCandidateGrpc(candidate, options.not_show_stakes, options.height).then((r) => {
34-
const result = r.toObject()
35-
this.contentExporter.print(result, this.skip_pip2bip, options)
36-
}
37-
)
38-
.catch(console.log);
39-
return Promise.resolve(undefined);
40-
}
33+
minterApi
34+
.api()
35+
.getCandidateGrpc(candidate, options.not_show_stakes, options.height)
36+
.then((r) => {
37+
const result = r.toObject();
38+
this.contentExporter.print(result, this.skip_pip2bip, options);
39+
})
40+
.catch(console.log);
41+
return Promise.resolve(undefined);
42+
}
4143

44+
@Option({
45+
flags: '--height [number]',
46+
name: 'Height',
47+
description:
48+
'Blockchain state height for the current request. Optional, the last default state of the node is used',
49+
})
50+
parseNumber(val: string): number {
51+
return Number(val);
52+
}
4253

54+
@Option({
55+
flags: '--not_show_stakes [boolean]',
56+
description:
57+
'Do not display a list of steaks. Note: used_slots, uniq_users, min_stake will be filled',
58+
defaultValue: true,
59+
})
60+
parseBoolean(val: string): boolean {
61+
return JSON.parse(val);
62+
}
4363

44-
@Option({
45-
flags: '--height [number]',
46-
name: 'Height',
47-
description:
48-
'Blockchain state height for the current request. Optional, the last default state of the node is used',
49-
})
50-
parseNumber(val: string): number {
51-
return Number(val);
52-
}
64+
@Option({
65+
flags: '-c, --config [string]',
66+
description: 'path to config file',
67+
defaultValue: 'config.yml',
68+
})
69+
parseConfig(val: string): string {
70+
return val;
71+
}
5372

54-
@Option({
55-
flags: '--not_show_stakes [boolean]',
56-
description:
57-
'Do not display a list of steaks. Note: used_slots, uniq_users, min_stake will be filled',
58-
defaultValue: true,
59-
})
60-
parseBoolean(val: string): boolean {
61-
return JSON.parse(val);
62-
}
73+
@Option({
74+
flags: '-p, --patch [string]',
75+
description: 'path JMESPath format',
76+
// defaultValue: 'status',
77+
})
78+
parsePatch(val: string): string {
79+
return val;
80+
}
6381

64-
@Option({
65-
flags: '-c, --config [string]',
66-
description: 'path to config file',
67-
defaultValue: 'config.yml',
68-
})
69-
parseConfig(val: string): string {
70-
return val;
71-
}
82+
@Option({
83+
flags: '-pl, --patches [boolean]',
84+
description: 'list of patches',
85+
// defaultValue: false,
86+
})
87+
parsePatches(val: string): boolean {
88+
return JSON.parse(val);
89+
}
7290

73-
@Option({
74-
flags: '-p, --patch [string]',
75-
description: 'path JMESPath format',
76-
// defaultValue: 'status',
77-
})
78-
parsePatch(val: string): string {
79-
return val;
80-
}
81-
82-
@Option({
83-
flags: '-pl, --patches [boolean]',
84-
description: 'list of patches',
85-
// defaultValue: false,
86-
})
87-
parsePatches(val: string): boolean {
88-
return JSON.parse(val);
89-
}
90-
91-
@Option({
92-
flags: '--pretty [boolean]',
93-
description: 'Pretty',
94-
defaultValue: true,
95-
})
96-
parsePretty(val: string): boolean {
97-
return JSON.parse(val);
98-
}
99-
100-
@Option({
101-
flags: '--skip_pip2bip',
102-
name: 'skip_pip2bip',
103-
description: 'Skip convert PIP to BIP',
104-
defaultValue: false,
105-
})
106-
parseSkipPip2Bip(val: string): boolean {
107-
this.skip_pip2bip = true;
108-
return JSON.parse(val);
109-
}
91+
@Option({
92+
flags: '--pretty [boolean]',
93+
description: 'Pretty',
94+
defaultValue: true,
95+
})
96+
parsePretty(val: string): boolean {
97+
return JSON.parse(val);
98+
}
11099

100+
@Option({
101+
flags: '--skip_pip2bip',
102+
name: 'skip_pip2bip',
103+
description: 'Skip convert PIP to BIP',
104+
defaultValue: false,
105+
})
106+
parseSkipPip2Bip(val: string): boolean {
107+
this.skip_pip2bip = true;
108+
return JSON.parse(val);
109+
}
111110
}

0 commit comments

Comments
 (0)