@super-protocol/sp-cli 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -43
- package/dist/commands/account/base.d.ts +1 -2
- package/dist/commands/account/base.js +4 -11
- package/dist/commands/account/forget.d.ts +2 -1
- package/dist/commands/account/forget.js +21 -4
- package/dist/commands/account/login.js +3 -8
- package/dist/commands/base.js +96 -12
- package/dist/commands/storage/base.js +11 -11
- package/dist/commands/storage/select.js +3 -3
- package/dist/commands/storage/update.js +10 -10
- package/dist/commands/workflows/extend-lease.d.ts +1 -1
- package/dist/commands/workflows/extend-lease.js +2 -3
- package/dist/utils/prompt-flags.d.ts +20 -0
- package/dist/utils/prompt-flags.js +121 -0
- package/dist/utils/prompt.service.d.ts +16 -0
- package/dist/utils/prompt.service.js +75 -0
- package/dist/utils/tty.d.ts +1 -0
- package/dist/utils/tty.js +3 -0
- package/oclif.manifest.json +265 -160
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ $ npm install -g @super-protocol/sp-cli
|
|
|
21
21
|
$ sp COMMAND
|
|
22
22
|
running command...
|
|
23
23
|
$ sp (--version)
|
|
24
|
-
@super-protocol/sp-cli/0.0.
|
|
24
|
+
@super-protocol/sp-cli/0.0.8 linux-x64 node-v22.21.1
|
|
25
25
|
$ sp --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ sp COMMAND
|
|
@@ -53,14 +53,15 @@ Purge all account details
|
|
|
53
53
|
|
|
54
54
|
```
|
|
55
55
|
USAGE
|
|
56
|
-
$ sp account forget [--json] [
|
|
56
|
+
$ sp account forget -n <value> [--json] [--tty] [-f]
|
|
57
57
|
|
|
58
58
|
FLAGS
|
|
59
59
|
-f, --force Force deletion without confirmation
|
|
60
|
-
-n, --name=<value> Configuration name to delete
|
|
60
|
+
-n, --name=<value> (required) Configuration name to delete
|
|
61
61
|
|
|
62
62
|
GLOBAL FLAGS
|
|
63
|
-
--json
|
|
63
|
+
--json Format output as json.
|
|
64
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
64
65
|
|
|
65
66
|
DESCRIPTION
|
|
66
67
|
Purge all account details
|
|
@@ -73,7 +74,7 @@ EXAMPLES
|
|
|
73
74
|
$ sp account forget --name "My Account" --force
|
|
74
75
|
```
|
|
75
76
|
|
|
76
|
-
_See code: [src/commands/account/forget.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
77
|
+
_See code: [src/commands/account/forget.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/account/forget.ts)_
|
|
77
78
|
|
|
78
79
|
## `sp account get-sppi`
|
|
79
80
|
|
|
@@ -81,10 +82,11 @@ Get SPPI (Super Protocol incentive tokens)
|
|
|
81
82
|
|
|
82
83
|
```
|
|
83
84
|
USAGE
|
|
84
|
-
$ sp account get-sppi [--json]
|
|
85
|
+
$ sp account get-sppi [--json] [--tty]
|
|
85
86
|
|
|
86
87
|
GLOBAL FLAGS
|
|
87
|
-
--json
|
|
88
|
+
--json Format output as json.
|
|
89
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
88
90
|
|
|
89
91
|
DESCRIPTION
|
|
90
92
|
Get SPPI (Super Protocol incentive tokens)
|
|
@@ -93,7 +95,7 @@ EXAMPLES
|
|
|
93
95
|
$ sp account get-sppi
|
|
94
96
|
```
|
|
95
97
|
|
|
96
|
-
_See code: [src/commands/account/get-sppi.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
98
|
+
_See code: [src/commands/account/get-sppi.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/account/get-sppi.ts)_
|
|
97
99
|
|
|
98
100
|
## `sp account info`
|
|
99
101
|
|
|
@@ -101,19 +103,20 @@ Information about current authorized user
|
|
|
101
103
|
|
|
102
104
|
```
|
|
103
105
|
USAGE
|
|
104
|
-
$ sp account info [--json] [--detail]
|
|
106
|
+
$ sp account info [--json] [--tty] [--detail]
|
|
105
107
|
|
|
106
108
|
FLAGS
|
|
107
109
|
--detail Detailed information about Account
|
|
108
110
|
|
|
109
111
|
GLOBAL FLAGS
|
|
110
|
-
--json
|
|
112
|
+
--json Format output as json.
|
|
113
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
111
114
|
|
|
112
115
|
DESCRIPTION
|
|
113
116
|
Information about current authorized user
|
|
114
117
|
```
|
|
115
118
|
|
|
116
|
-
_See code: [src/commands/account/info.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
119
|
+
_See code: [src/commands/account/info.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/account/info.ts)_
|
|
117
120
|
|
|
118
121
|
## `sp account list`
|
|
119
122
|
|
|
@@ -121,10 +124,11 @@ List all Accounts
|
|
|
121
124
|
|
|
122
125
|
```
|
|
123
126
|
USAGE
|
|
124
|
-
$ sp account list [--json]
|
|
127
|
+
$ sp account list [--json] [--tty]
|
|
125
128
|
|
|
126
129
|
GLOBAL FLAGS
|
|
127
|
-
--json
|
|
130
|
+
--json Format output as json.
|
|
131
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
128
132
|
|
|
129
133
|
DESCRIPTION
|
|
130
134
|
List all Accounts
|
|
@@ -133,7 +137,7 @@ EXAMPLES
|
|
|
133
137
|
$ sp account list
|
|
134
138
|
```
|
|
135
139
|
|
|
136
|
-
_See code: [src/commands/account/list.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
140
|
+
_See code: [src/commands/account/list.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/account/list.ts)_
|
|
137
141
|
|
|
138
142
|
## `sp account login`
|
|
139
143
|
|
|
@@ -141,7 +145,7 @@ Login to SuperProtocol (sign up or sign in).
|
|
|
141
145
|
|
|
142
146
|
```
|
|
143
147
|
USAGE
|
|
144
|
-
$ sp account login [--json] [--name <value>] [--privateKey <value>] [-y]
|
|
148
|
+
$ sp account login [--json] [--tty] [--name <value>] [--privateKey <value>] [-y]
|
|
145
149
|
|
|
146
150
|
FLAGS
|
|
147
151
|
-y, --yes Skip questions (generate keys when needed).
|
|
@@ -149,7 +153,8 @@ FLAGS
|
|
|
149
153
|
--privateKey=<value> Account private key used for authentication
|
|
150
154
|
|
|
151
155
|
GLOBAL FLAGS
|
|
152
|
-
--json
|
|
156
|
+
--json Format output as json.
|
|
157
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
153
158
|
|
|
154
159
|
DESCRIPTION
|
|
155
160
|
Login to SuperProtocol (sign up or sign in).
|
|
@@ -161,7 +166,7 @@ EXAMPLES
|
|
|
161
166
|
$ sp account login
|
|
162
167
|
```
|
|
163
168
|
|
|
164
|
-
_See code: [src/commands/account/login.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
169
|
+
_See code: [src/commands/account/login.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/account/login.ts)_
|
|
165
170
|
|
|
166
171
|
## `sp account switch`
|
|
167
172
|
|
|
@@ -169,10 +174,11 @@ Switch to a different account
|
|
|
169
174
|
|
|
170
175
|
```
|
|
171
176
|
USAGE
|
|
172
|
-
$ sp account switch [--json]
|
|
177
|
+
$ sp account switch [--json] [--tty]
|
|
173
178
|
|
|
174
179
|
GLOBAL FLAGS
|
|
175
|
-
--json
|
|
180
|
+
--json Format output as json.
|
|
181
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
176
182
|
|
|
177
183
|
DESCRIPTION
|
|
178
184
|
Switch to a different account
|
|
@@ -181,7 +187,7 @@ EXAMPLES
|
|
|
181
187
|
$ sp account switch
|
|
182
188
|
```
|
|
183
189
|
|
|
184
|
-
_See code: [src/commands/account/switch.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
190
|
+
_See code: [src/commands/account/switch.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/account/switch.ts)_
|
|
185
191
|
|
|
186
192
|
## `sp autocomplete [SHELL]`
|
|
187
193
|
|
|
@@ -220,7 +226,7 @@ Download file or directory described in resource file
|
|
|
220
226
|
|
|
221
227
|
```
|
|
222
228
|
USAGE
|
|
223
|
-
$ sp files download RESOURCEFILE LOCALDIRECTORY [--json] [--maximum-concurrent <value>]
|
|
229
|
+
$ sp files download RESOURCEFILE LOCALDIRECTORY [--json] [--tty] [--maximum-concurrent <value>]
|
|
224
230
|
|
|
225
231
|
ARGUMENTS
|
|
226
232
|
RESOURCEFILE Path to a resource file
|
|
@@ -230,7 +236,8 @@ FLAGS
|
|
|
230
236
|
--maximum-concurrent=<value> [default: 1] Maximum concurrent pieces to download at once per transfer
|
|
231
237
|
|
|
232
238
|
GLOBAL FLAGS
|
|
233
|
-
--json
|
|
239
|
+
--json Format output as json.
|
|
240
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
234
241
|
|
|
235
242
|
DESCRIPTION
|
|
236
243
|
Download file or directory described in resource file
|
|
@@ -239,7 +246,7 @@ EXAMPLES
|
|
|
239
246
|
$ sp files download ./resource.json ./pathToDownload
|
|
240
247
|
```
|
|
241
248
|
|
|
242
|
-
_See code: [src/commands/files/download.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
249
|
+
_See code: [src/commands/files/download.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/files/download.ts)_
|
|
243
250
|
|
|
244
251
|
## `sp files upload PATH`
|
|
245
252
|
|
|
@@ -247,7 +254,7 @@ Upload file or directory to remote storage
|
|
|
247
254
|
|
|
248
255
|
```
|
|
249
256
|
USAGE
|
|
250
|
-
$ sp files upload PATH [--json] [--filename <value>] [--maximum-concurrent <value>] [--metadata <value>]
|
|
257
|
+
$ sp files upload PATH [--json] [--tty] [--filename <value>] [--maximum-concurrent <value>] [--metadata <value>]
|
|
251
258
|
[--output <value>] [--skip-encryption] [--sync]
|
|
252
259
|
|
|
253
260
|
ARGUMENTS
|
|
@@ -263,7 +270,8 @@ FLAGS
|
|
|
263
270
|
--sync Sync mode: delete files in target that don't exist in source
|
|
264
271
|
|
|
265
272
|
GLOBAL FLAGS
|
|
266
|
-
--json
|
|
273
|
+
--json Format output as json.
|
|
274
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
267
275
|
|
|
268
276
|
DESCRIPTION
|
|
269
277
|
Upload file or directory to remote storage
|
|
@@ -272,7 +280,7 @@ EXAMPLES
|
|
|
272
280
|
$ sp files upload ./file.txt
|
|
273
281
|
```
|
|
274
282
|
|
|
275
|
-
_See code: [src/commands/files/upload.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
283
|
+
_See code: [src/commands/files/upload.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/files/upload.ts)_
|
|
276
284
|
|
|
277
285
|
## `sp help [COMMAND]`
|
|
278
286
|
|
|
@@ -300,7 +308,7 @@ Login to SuperProtocol (sign up or sign in).
|
|
|
300
308
|
|
|
301
309
|
```
|
|
302
310
|
USAGE
|
|
303
|
-
$ sp login [--json] [--name <value>] [--privateKey <value>] [-y]
|
|
311
|
+
$ sp login [--json] [--tty] [--name <value>] [--privateKey <value>] [-y]
|
|
304
312
|
|
|
305
313
|
FLAGS
|
|
306
314
|
-y, --yes Skip questions (generate keys when needed).
|
|
@@ -308,7 +316,8 @@ FLAGS
|
|
|
308
316
|
--privateKey=<value> Account private key used for authentication
|
|
309
317
|
|
|
310
318
|
GLOBAL FLAGS
|
|
311
|
-
--json
|
|
319
|
+
--json Format output as json.
|
|
320
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
312
321
|
|
|
313
322
|
DESCRIPTION
|
|
314
323
|
Login to SuperProtocol (sign up or sign in).
|
|
@@ -326,14 +335,15 @@ Create a new storage entry from file or interactive prompts.
|
|
|
326
335
|
|
|
327
336
|
```
|
|
328
337
|
USAGE
|
|
329
|
-
$ sp storage create [--json] [-f <value>] [--notDefault]
|
|
338
|
+
$ sp storage create [--json] [--tty] [-f <value>] [--notDefault]
|
|
330
339
|
|
|
331
340
|
FLAGS
|
|
332
341
|
-f, --fromFile=<value> Path to a JSON file that contains AddStorageDto payload.
|
|
333
342
|
--notDefault Skip setting the created storage as default.
|
|
334
343
|
|
|
335
344
|
GLOBAL FLAGS
|
|
336
|
-
--json
|
|
345
|
+
--json Format output as json.
|
|
346
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
337
347
|
|
|
338
348
|
DESCRIPTION
|
|
339
349
|
Create a new storage entry from file or interactive prompts.
|
|
@@ -346,7 +356,7 @@ EXAMPLES
|
|
|
346
356
|
$ sp storage create --not-default
|
|
347
357
|
```
|
|
348
358
|
|
|
349
|
-
_See code: [src/commands/storage/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
359
|
+
_See code: [src/commands/storage/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/storage/create.ts)_
|
|
350
360
|
|
|
351
361
|
## `sp storage select`
|
|
352
362
|
|
|
@@ -354,10 +364,11 @@ Select a storage that will be used by subsequent commands.
|
|
|
354
364
|
|
|
355
365
|
```
|
|
356
366
|
USAGE
|
|
357
|
-
$ sp storage select [--json]
|
|
367
|
+
$ sp storage select [--json] [--tty]
|
|
358
368
|
|
|
359
369
|
GLOBAL FLAGS
|
|
360
|
-
--json
|
|
370
|
+
--json Format output as json.
|
|
371
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
361
372
|
|
|
362
373
|
DESCRIPTION
|
|
363
374
|
Select a storage that will be used by subsequent commands.
|
|
@@ -366,7 +377,7 @@ EXAMPLES
|
|
|
366
377
|
$ sp storage select
|
|
367
378
|
```
|
|
368
379
|
|
|
369
|
-
_See code: [src/commands/storage/select.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
380
|
+
_See code: [src/commands/storage/select.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/storage/select.ts)_
|
|
370
381
|
|
|
371
382
|
## `sp storage show`
|
|
372
383
|
|
|
@@ -374,10 +385,11 @@ Show current selected storage
|
|
|
374
385
|
|
|
375
386
|
```
|
|
376
387
|
USAGE
|
|
377
|
-
$ sp storage show [--json]
|
|
388
|
+
$ sp storage show [--json] [--tty]
|
|
378
389
|
|
|
379
390
|
GLOBAL FLAGS
|
|
380
|
-
--json
|
|
391
|
+
--json Format output as json.
|
|
392
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
381
393
|
|
|
382
394
|
DESCRIPTION
|
|
383
395
|
Show current selected storage
|
|
@@ -386,7 +398,7 @@ EXAMPLES
|
|
|
386
398
|
$ sp storage show
|
|
387
399
|
```
|
|
388
400
|
|
|
389
|
-
_See code: [src/commands/storage/show.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
401
|
+
_See code: [src/commands/storage/show.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/storage/show.ts)_
|
|
390
402
|
|
|
391
403
|
## `sp storage update`
|
|
392
404
|
|
|
@@ -394,14 +406,15 @@ Update the configuration of an existing storage.
|
|
|
394
406
|
|
|
395
407
|
```
|
|
396
408
|
USAGE
|
|
397
|
-
$ sp storage update [--json] [-f <value>] [-i <value>]
|
|
409
|
+
$ sp storage update [--json] [--tty] [-f <value>] [-i <value>]
|
|
398
410
|
|
|
399
411
|
FLAGS
|
|
400
412
|
-f, --fromFile=<value> Path to a JSON file that contains UpdateStorageDto payload.
|
|
401
413
|
-i, --id=<value> Storage ID to update
|
|
402
414
|
|
|
403
415
|
GLOBAL FLAGS
|
|
404
|
-
--json
|
|
416
|
+
--json Format output as json.
|
|
417
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
405
418
|
|
|
406
419
|
DESCRIPTION
|
|
407
420
|
Update the configuration of an existing storage.
|
|
@@ -412,7 +425,7 @@ EXAMPLES
|
|
|
412
425
|
$ sp storage update --id=2de3e3a4-0000-1111-2222-333344445555
|
|
413
426
|
```
|
|
414
427
|
|
|
415
|
-
_See code: [src/commands/storage/update.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
428
|
+
_See code: [src/commands/storage/update.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/storage/update.ts)_
|
|
416
429
|
|
|
417
430
|
## `sp workflows extend-lease ORDERID`
|
|
418
431
|
|
|
@@ -420,7 +433,7 @@ Replenish deposit for a workflow to extend its lease time
|
|
|
420
433
|
|
|
421
434
|
```
|
|
422
435
|
USAGE
|
|
423
|
-
$ sp workflows extend-lease ORDERID [--json] [--minutes <value>] [--sppi <value>] [-y]
|
|
436
|
+
$ sp workflows extend-lease ORDERID [--json] [--tty] [--minutes <value>] [--sppi <value>] [-y]
|
|
424
437
|
|
|
425
438
|
ARGUMENTS
|
|
426
439
|
ORDERID Order ID
|
|
@@ -431,7 +444,8 @@ FLAGS
|
|
|
431
444
|
--sppi=<value> SPPI token amount to add to the order
|
|
432
445
|
|
|
433
446
|
GLOBAL FLAGS
|
|
434
|
-
--json
|
|
447
|
+
--json Format output as json.
|
|
448
|
+
--[no-]tty Force or disable interactive mode (use --no-tty to disable).
|
|
435
449
|
|
|
436
450
|
DESCRIPTION
|
|
437
451
|
Replenish deposit for a workflow to extend its lease time
|
|
@@ -444,5 +458,5 @@ EXAMPLES
|
|
|
444
458
|
$ sp workflows extend-lease <orderId> --sppi 2 --yes
|
|
445
459
|
```
|
|
446
460
|
|
|
447
|
-
_See code: [src/commands/workflows/extend-lease.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.
|
|
461
|
+
_See code: [src/commands/workflows/extend-lease.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.8/src/commands/workflows/extend-lease.ts)_
|
|
448
462
|
<!-- commandsstop -->
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { select } from '@clack/prompts';
|
|
2
1
|
import type { Command } from '@oclif/core';
|
|
3
2
|
import type { AccountManager } from '../../managers/index.js';
|
|
3
|
+
import { type SelectOptions } from '../../utils/prompt.service.js';
|
|
4
4
|
import { BaseCommand } from '../base.js';
|
|
5
|
-
type SelectOptions<T> = Parameters<typeof select<T>>[0];
|
|
6
5
|
type ProviderInitOptions = {
|
|
7
6
|
assumeYes?: boolean;
|
|
8
7
|
enableAuth?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { promptService } from '../../utils/prompt.service.js';
|
|
2
2
|
import { BaseCommand } from '../base.js';
|
|
3
3
|
export class BaseAccountCommand extends BaseCommand {
|
|
4
4
|
async initAccountContext(providerOptions = {}) {
|
|
@@ -14,23 +14,17 @@ export class BaseAccountCommand extends BaseCommand {
|
|
|
14
14
|
}
|
|
15
15
|
async interactWithUser(accountManager) {
|
|
16
16
|
this.warn("Account doesn't exist in current configuration");
|
|
17
|
-
const ask = await confirm({
|
|
17
|
+
const ask = await promptService.confirm({
|
|
18
18
|
message: 'Do you want to create a new account?',
|
|
19
19
|
});
|
|
20
|
-
if (isCancel(ask)) {
|
|
21
|
-
this.error('Operation cancelled.', { exit: 1 });
|
|
22
|
-
}
|
|
23
20
|
if (ask) {
|
|
24
21
|
const account = await accountManager.create();
|
|
25
22
|
this.log('Generated new keyPair for new account.');
|
|
26
23
|
return account;
|
|
27
24
|
}
|
|
28
|
-
const privateKeyInput = await password({
|
|
25
|
+
const privateKeyInput = await promptService.password({
|
|
29
26
|
message: 'Please input your privateKey for using in account',
|
|
30
27
|
});
|
|
31
|
-
if (isCancel(privateKeyInput)) {
|
|
32
|
-
this.error('Operation cancelled.', { exit: 1 });
|
|
33
|
-
}
|
|
34
28
|
const privateKey = privateKeyInput.trim();
|
|
35
29
|
try {
|
|
36
30
|
const account = await accountManager.createFromKey(privateKey);
|
|
@@ -43,7 +37,6 @@ export class BaseAccountCommand extends BaseCommand {
|
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
async selectPrompt(options) {
|
|
46
|
-
|
|
47
|
-
return this.ensurePromptValue(result);
|
|
40
|
+
return promptService.select(options);
|
|
48
41
|
}
|
|
49
42
|
}
|
|
@@ -5,9 +5,10 @@ export default class AccountForget extends BaseAccountCommand<typeof AccountForg
|
|
|
5
5
|
static examples: string[];
|
|
6
6
|
static flags: {
|
|
7
7
|
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
-
name: import("@oclif/core/interfaces").OptionFlag<string
|
|
8
|
+
name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
9
|
};
|
|
10
10
|
private configFileManager;
|
|
11
11
|
init(): Promise<void>;
|
|
12
12
|
run(): Promise<void>;
|
|
13
|
+
private updateNameFlagOptions;
|
|
13
14
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
+
import { AppContainer } from '../../lib/container.js';
|
|
2
3
|
import { BaseAccountCommand } from './base.js';
|
|
4
|
+
const buildConfigNameFlag = (options = []) => options.length
|
|
5
|
+
? Flags.option({
|
|
6
|
+
char: 'n',
|
|
7
|
+
description: 'Configuration name to delete',
|
|
8
|
+
options,
|
|
9
|
+
required: true,
|
|
10
|
+
})()
|
|
11
|
+
: Flags.string({
|
|
12
|
+
char: 'n',
|
|
13
|
+
description: 'Configuration name to delete',
|
|
14
|
+
required: true,
|
|
15
|
+
});
|
|
3
16
|
export default class AccountForget extends BaseAccountCommand {
|
|
4
17
|
static authenticate = false;
|
|
5
18
|
static description = 'Purge all account details';
|
|
@@ -14,13 +27,11 @@ export default class AccountForget extends BaseAccountCommand {
|
|
|
14
27
|
default: false,
|
|
15
28
|
description: 'Force deletion without confirmation',
|
|
16
29
|
}),
|
|
17
|
-
name:
|
|
18
|
-
char: 'n',
|
|
19
|
-
description: 'Configuration name to delete',
|
|
20
|
-
}),
|
|
30
|
+
name: buildConfigNameFlag(),
|
|
21
31
|
};
|
|
22
32
|
configFileManager;
|
|
23
33
|
async init() {
|
|
34
|
+
await this.updateNameFlagOptions();
|
|
24
35
|
await super.init();
|
|
25
36
|
await this.container.initConfigFileManager().build();
|
|
26
37
|
this.configFileManager = this.container.configFileManager;
|
|
@@ -29,4 +40,10 @@ export default class AccountForget extends BaseAccountCommand {
|
|
|
29
40
|
const { force, name } = this.flags;
|
|
30
41
|
await this.configFileManager.deleteConfigByName(name, force);
|
|
31
42
|
}
|
|
43
|
+
async updateNameFlagOptions() {
|
|
44
|
+
const { configFileManager } = await AppContainer.container.initConfigFileManager().build();
|
|
45
|
+
const configs = configFileManager.getConfigsWithNames();
|
|
46
|
+
const options = configs.map((config) => config.name);
|
|
47
|
+
this.constructor.flags.name = buildConfigNameFlag(options);
|
|
48
|
+
}
|
|
32
49
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { confirm, isCancel, text } from '@clack/prompts';
|
|
4
3
|
import { Flags } from '@oclif/core';
|
|
5
4
|
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
6
5
|
import { PROVIDER_URL } from '../../constants.js';
|
|
7
6
|
import { AuthService } from '../../services/auth.service.js';
|
|
8
7
|
import { StorageService } from '../../services/storage.service.js';
|
|
9
8
|
import { getConfigNameFromCredentials } from '../../utils/helper.js';
|
|
9
|
+
import { promptService } from '../../utils/prompt.service.js';
|
|
10
10
|
import { BaseAccountCommand } from './base.js';
|
|
11
11
|
export default class AccountLoginCommand extends BaseAccountCommand {
|
|
12
12
|
static aliases = ['login'];
|
|
@@ -36,8 +36,7 @@ export default class AccountLoginCommand extends BaseAccountCommand {
|
|
|
36
36
|
configFileManager;
|
|
37
37
|
shouldSkipLogin = false;
|
|
38
38
|
async inputPrompt(options) {
|
|
39
|
-
|
|
40
|
-
return this.ensurePromptValue(result);
|
|
39
|
+
return promptService.text(options);
|
|
41
40
|
}
|
|
42
41
|
async checkStorage() {
|
|
43
42
|
await this.container
|
|
@@ -98,11 +97,7 @@ export default class AccountLoginCommand extends BaseAccountCommand {
|
|
|
98
97
|
return trimmed || fallback;
|
|
99
98
|
}
|
|
100
99
|
async confirmPrompt(message, initialValue = true) {
|
|
101
|
-
|
|
102
|
-
if (isCancel(result)) {
|
|
103
|
-
this.error('Operation cancelled.', { exit: 1 });
|
|
104
|
-
}
|
|
105
|
-
return Boolean(result);
|
|
100
|
+
return promptService.confirm({ initialValue, message });
|
|
106
101
|
}
|
|
107
102
|
createAccountFromKey(privateKey) {
|
|
108
103
|
try {
|
package/dist/commands/base.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import { isCancel } from '@clack/prompts';
|
|
2
1
|
import { Command, Flags } from '@oclif/core';
|
|
3
2
|
import { AppContainer } from '../lib/container.js';
|
|
4
3
|
import logger from '../logger.js';
|
|
4
|
+
import { findMissingRequiredArgs, findMissingRequiredFlags, formatMissingArgsError, formatMissingFlagsError, promptForArg, promptForFlag, } from '../utils/prompt-flags.js';
|
|
5
|
+
import { promptService } from '../utils/prompt.service.js';
|
|
6
|
+
import { isInteractiveMode } from '../utils/tty.js';
|
|
7
|
+
const relaxRequired = (definitions) => {
|
|
8
|
+
if (!definitions) {
|
|
9
|
+
return definitions;
|
|
10
|
+
}
|
|
11
|
+
return Object.fromEntries(Object.entries(definitions).map(([name, definition]) => [
|
|
12
|
+
name,
|
|
13
|
+
{
|
|
14
|
+
...definition,
|
|
15
|
+
required: false,
|
|
16
|
+
},
|
|
17
|
+
]));
|
|
18
|
+
};
|
|
5
19
|
export class BaseCommand extends Command {
|
|
6
20
|
static authenticate = true;
|
|
7
21
|
static baseFlags = {
|
|
@@ -11,6 +25,12 @@ export class BaseCommand extends Command {
|
|
|
11
25
|
required: false,
|
|
12
26
|
summary: 'Specify config file.',
|
|
13
27
|
}),
|
|
28
|
+
tty: Flags.boolean({
|
|
29
|
+
allowNo: true,
|
|
30
|
+
helpGroup: 'GLOBAL',
|
|
31
|
+
required: false,
|
|
32
|
+
summary: 'Force or disable interactive mode (use --no-tty to disable).',
|
|
33
|
+
}),
|
|
14
34
|
};
|
|
15
35
|
static enableJsonFlag = true;
|
|
16
36
|
args;
|
|
@@ -22,24 +42,88 @@ export class BaseCommand extends Command {
|
|
|
22
42
|
this.logger = logger.getPino();
|
|
23
43
|
}
|
|
24
44
|
ensurePromptValue(value, errorMessage = 'Operation cancelled.') {
|
|
25
|
-
|
|
26
|
-
|
|
45
|
+
try {
|
|
46
|
+
return promptService.ensureValue(value, errorMessage);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
27
50
|
}
|
|
28
|
-
return value;
|
|
29
51
|
}
|
|
30
52
|
async init() {
|
|
31
53
|
await super.init();
|
|
32
|
-
const {
|
|
33
|
-
|
|
34
|
-
|
|
54
|
+
const allFlags = { ...this.ctor.flags, ...super.ctor.baseFlags };
|
|
55
|
+
const relaxedArgs = relaxRequired(this.ctor.args);
|
|
56
|
+
const relaxedFlags = relaxRequired(this.ctor.flags);
|
|
57
|
+
const relaxedBaseFlags = relaxRequired(super.ctor.baseFlags);
|
|
58
|
+
let parsedResult = await this.parse({
|
|
59
|
+
args: relaxedArgs,
|
|
60
|
+
baseFlags: relaxedBaseFlags,
|
|
35
61
|
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
36
|
-
flags:
|
|
37
|
-
strict:
|
|
62
|
+
flags: relaxedFlags,
|
|
63
|
+
strict: false,
|
|
38
64
|
});
|
|
39
|
-
|
|
40
|
-
|
|
65
|
+
const isInteractive = isInteractiveMode(parsedResult.flags.tty);
|
|
66
|
+
const missingFlags = await findMissingRequiredFlags(parsedResult.flags, allFlags);
|
|
67
|
+
const missingArgs = await findMissingRequiredArgs(parsedResult.args, this.ctor.args);
|
|
68
|
+
if (missingFlags.length > 0 || missingArgs.length > 0) {
|
|
69
|
+
if (!isInteractive) {
|
|
70
|
+
const errors = [];
|
|
71
|
+
if (missingFlags.length > 0) {
|
|
72
|
+
errors.push(formatMissingFlagsError(missingFlags));
|
|
73
|
+
}
|
|
74
|
+
if (missingArgs.length > 0) {
|
|
75
|
+
errors.push(formatMissingArgsError(missingArgs));
|
|
76
|
+
}
|
|
77
|
+
this.error(errors.join(' '), { exit: 1 });
|
|
78
|
+
}
|
|
79
|
+
const argValues = [];
|
|
80
|
+
for (const missingArg of missingArgs) {
|
|
81
|
+
const value = await promptForArg(missingArg);
|
|
82
|
+
argValues.push(String(value));
|
|
83
|
+
}
|
|
84
|
+
const flagPairs = [];
|
|
85
|
+
for (const missingFlag of missingFlags) {
|
|
86
|
+
const value = await promptForFlag(missingFlag);
|
|
87
|
+
if (missingFlag.type === 'boolean') {
|
|
88
|
+
const boolValue = Boolean(value);
|
|
89
|
+
if (boolValue) {
|
|
90
|
+
flagPairs.push(`--${missingFlag.name}`);
|
|
91
|
+
}
|
|
92
|
+
else if ('allowNo' in missingFlag.definition &&
|
|
93
|
+
Boolean(missingFlag.definition.allowNo)) {
|
|
94
|
+
flagPairs.push(`--no-${missingFlag.name}`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.error(`Flag --${missingFlag.name} is required and only supports "true".`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
flagPairs.push(`--${missingFlag.name}`, String(value));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const updatedArgv = [...this.argv, ...argValues, ...flagPairs];
|
|
105
|
+
this.argv = updatedArgv;
|
|
106
|
+
parsedResult = await this.parse({
|
|
107
|
+
args: this.ctor.args,
|
|
108
|
+
baseFlags: super.ctor.baseFlags,
|
|
109
|
+
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
110
|
+
flags: this.ctor.flags,
|
|
111
|
+
strict: this.ctor.strict,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else if (this.ctor.strict) {
|
|
115
|
+
parsedResult = await this.parse({
|
|
116
|
+
args: this.ctor.args,
|
|
117
|
+
baseFlags: super.ctor.baseFlags,
|
|
118
|
+
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
119
|
+
flags: this.ctor.flags,
|
|
120
|
+
strict: true,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
this.flags = parsedResult.flags;
|
|
124
|
+
this.args = parsedResult.args;
|
|
41
125
|
this.container = AppContainer.container.setupRuntimeConfig({
|
|
42
|
-
configFile: flags.config,
|
|
126
|
+
configFile: parsedResult.flags.config,
|
|
43
127
|
});
|
|
44
128
|
}
|
|
45
129
|
}
|