|
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'; |
4 | 4 |
|
5 | 5 | @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', |
10 | 10 | }) |
11 | 11 | export class CandidateCommand extends CommandRunner { |
12 | | - private skip_pip2bip = false; |
| 12 | + private skip_pip2bip = false; |
13 | 13 |
|
14 | | - constructor(private contentExporter: ContentExporter) { |
15 | | - super(); |
16 | | - } |
| 14 | + constructor(private contentExporter: ContentExporter) { |
| 15 | + super(); |
| 16 | + } |
17 | 17 |
|
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); |
32 | 32 |
|
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 | + } |
41 | 43 |
|
| 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 | + } |
42 | 53 |
|
| 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 | + } |
43 | 63 |
|
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 | + } |
53 | 72 |
|
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 | + } |
63 | 81 |
|
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 | + } |
72 | 90 |
|
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 | + } |
110 | 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 | + } |
111 | 110 | } |
0 commit comments