@0xobelisk/sui-cli 1.2.0-pre.3 → 1.2.0-pre.33
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/dist/dubhe.js +49 -66
- package/dist/dubhe.js.map +1 -1
- package/package.json +4 -3
- package/src/commands/build.ts +3 -2
- package/src/commands/call.ts +83 -83
- package/src/commands/convertJson.ts +49 -0
- package/src/commands/doctor.ts +348 -0
- package/src/commands/index.ts +14 -7
- package/src/commands/info.ts +49 -0
- package/src/commands/loadMetadata.ts +50 -0
- package/src/commands/localnode.ts +19 -11
- package/src/commands/publish.ts +3 -1
- package/src/commands/query.ts +101 -101
- package/src/commands/schemagen.ts +4 -1
- package/src/commands/switchEnv.ts +24 -0
- package/src/commands/test.ts +1 -1
- package/src/commands/upgrade.ts +38 -38
- package/src/dubhe.ts +11 -3
- package/src/utils/callHandler.ts +118 -118
- package/src/utils/index.ts +2 -2
- package/src/utils/metadataHandler.ts +16 -0
- package/src/utils/publishHandler.ts +94 -269
- package/src/utils/queryStorage.ts +141 -141
- package/src/utils/startNode.ts +161 -106
- package/src/utils/storeConfig.ts +6 -12
- package/src/utils/upgradeHandler.ts +250 -249
- package/src/utils/utils.ts +291 -35
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CommandModule } from 'yargs';
|
|
2
|
+
import { logError, initializeDubhe } from '../utils';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
dotenv.config();
|
|
6
|
+
|
|
7
|
+
type Options = {
|
|
8
|
+
network: any;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const InfoCommand: CommandModule<Options, Options> = {
|
|
12
|
+
command: 'info',
|
|
13
|
+
describe: 'Get information about the current Sui node',
|
|
14
|
+
builder(yargs) {
|
|
15
|
+
return yargs.options({
|
|
16
|
+
network: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
|
|
19
|
+
default: 'localnet',
|
|
20
|
+
desc: 'Node network (mainnet/testnet/devnet/localnet)'
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
handler: async ({ network }) => {
|
|
25
|
+
try {
|
|
26
|
+
const dubhe = initializeDubhe({ network });
|
|
27
|
+
const keypair = dubhe.getSigner();
|
|
28
|
+
|
|
29
|
+
console.log(chalk.blue('Account Information:'));
|
|
30
|
+
console.log(` Network: ${chalk.green(network)}`);
|
|
31
|
+
console.log(` Address: ${chalk.green(keypair.toSuiAddress())}`);
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const balance = await dubhe.getBalance('0x2::sui::SUI');
|
|
35
|
+
const suiBalance = (Number(balance.totalBalance) / 10 ** 9).toFixed(4);
|
|
36
|
+
console.log(` Balance: ${chalk.green(suiBalance)} SUI`);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.log(
|
|
39
|
+
` Balance: ${chalk.red('Failed to fetch balance')} ${chalk.gray('(Network error)')}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
logError(error);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default InfoCommand;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CommandModule } from 'yargs';
|
|
2
|
+
import { logError } from '../utils/errors';
|
|
3
|
+
import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
4
|
+
import { loadMetadataHandler } from '../utils/metadataHandler';
|
|
5
|
+
|
|
6
|
+
type Options = {
|
|
7
|
+
network: any;
|
|
8
|
+
'config-path': string;
|
|
9
|
+
'package-id'?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const commandModule: CommandModule<Options, Options> = {
|
|
13
|
+
command: 'load-metadata',
|
|
14
|
+
|
|
15
|
+
describe: 'Load metadata for a package',
|
|
16
|
+
|
|
17
|
+
builder(yargs) {
|
|
18
|
+
return yargs.options({
|
|
19
|
+
network: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
|
|
22
|
+
default: 'localnet',
|
|
23
|
+
desc: 'Node network (mainnet/testnet/devnet/localnet)'
|
|
24
|
+
},
|
|
25
|
+
'config-path': {
|
|
26
|
+
type: 'string',
|
|
27
|
+
desc: 'Configuration file path',
|
|
28
|
+
default: 'dubhe.config.ts'
|
|
29
|
+
},
|
|
30
|
+
'package-id': {
|
|
31
|
+
type: 'string',
|
|
32
|
+
desc: 'Package ID to load metadata for',
|
|
33
|
+
optional: true
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
async handler({ network, 'config-path': configPath, 'package-id': packageId }) {
|
|
39
|
+
try {
|
|
40
|
+
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
41
|
+
await loadMetadataHandler(dubheConfig, network, packageId);
|
|
42
|
+
} catch (error: any) {
|
|
43
|
+
logError(error);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default commandModule;
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
2
|
import { startLocalNode } from '../utils/startNode';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type Options = {
|
|
5
|
+
'data-dir': string;
|
|
6
|
+
force: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const commandModule: CommandModule<Options, Options> = {
|
|
5
10
|
command: 'node',
|
|
6
11
|
|
|
7
12
|
describe: 'Manage local Sui node',
|
|
8
13
|
|
|
9
|
-
builder
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
builder: {
|
|
15
|
+
'data-dir': {
|
|
16
|
+
type: 'string',
|
|
17
|
+
default: '.chk',
|
|
18
|
+
desc: 'Path to the data directory'
|
|
19
|
+
},
|
|
20
|
+
force: {
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
default: false,
|
|
23
|
+
desc: 'Force restart: stop existing node and remove data directory'
|
|
24
|
+
}
|
|
17
25
|
},
|
|
18
26
|
|
|
19
|
-
async handler(
|
|
27
|
+
async handler({ 'data-dir': data_dir, force }) {
|
|
20
28
|
try {
|
|
21
|
-
await startLocalNode(
|
|
29
|
+
await startLocalNode(data_dir, force);
|
|
22
30
|
} catch (error) {
|
|
23
31
|
console.error('Error executing command:', error);
|
|
24
32
|
process.exit(1);
|
package/src/commands/publish.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { CommandModule } from 'yargs';
|
|
|
2
2
|
import { logError } from '../utils/errors';
|
|
3
3
|
import { publishHandler } from '../utils';
|
|
4
4
|
import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
5
|
+
import { execSync } from 'child_process';
|
|
5
6
|
|
|
6
7
|
type Options = {
|
|
7
8
|
network: any;
|
|
@@ -38,7 +39,8 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
38
39
|
async handler({ network, 'config-path': configPath, 'gas-budget': gasBudget }) {
|
|
39
40
|
try {
|
|
40
41
|
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
41
|
-
|
|
42
|
+
execSync(`pnpm dubhe convert-json --config-path ${configPath}`, { encoding: 'utf-8' })
|
|
43
|
+
await publishHandler(dubheConfig, network, gasBudget);
|
|
42
44
|
} catch (error: any) {
|
|
43
45
|
logError(error);
|
|
44
46
|
process.exit(1);
|
package/src/commands/query.ts
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import type { CommandModule } from 'yargs';
|
|
2
|
-
import { logError } from '../utils/errors';
|
|
3
|
-
import { queryStorage } from '../utils';
|
|
4
|
-
import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
1
|
+
// import type { CommandModule } from 'yargs';
|
|
2
|
+
// import { logError } from '../utils/errors';
|
|
3
|
+
// import { queryStorage } from '../utils';
|
|
4
|
+
// import { loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
5
5
|
|
|
6
|
-
type Options = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
6
|
+
// type Options = {
|
|
7
|
+
// network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
8
|
+
// 'config-path'?: string;
|
|
9
|
+
// schema: string;
|
|
10
|
+
// 'object-id'?: string;
|
|
11
|
+
// 'package-id'?: string;
|
|
12
|
+
// 'metadata-path'?: string;
|
|
13
|
+
// params?: any[];
|
|
14
|
+
// };
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const commandModule: CommandModule<Options, Options> = {
|
|
39
|
-
|
|
16
|
+
// /**
|
|
17
|
+
// * CLI command module for querying schema struct state
|
|
18
|
+
// *
|
|
19
|
+
// * Examples:
|
|
20
|
+
// *
|
|
21
|
+
// * 1. Query StorageValue (no params required):
|
|
22
|
+
// * ```bash
|
|
23
|
+
// * dubhe query --config-path dubhe.config.ts --network devnet --schema counter --field value
|
|
24
|
+
// * ```
|
|
25
|
+
// *
|
|
26
|
+
// * 2. Query StorageMap (one param required):
|
|
27
|
+
// * ```bash
|
|
28
|
+
// * dubhe query --config-path dubhe.config.ts --network devnet --schema token --field balances \
|
|
29
|
+
// * --params "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
|
|
30
|
+
// * ```
|
|
31
|
+
// *
|
|
32
|
+
// * 3. Query StorageDoubleMap (two params required):
|
|
33
|
+
// * ```bash
|
|
34
|
+
// * dubhe query --config-path dubhe.config.ts --network devnet --schema game --field player_relations \
|
|
35
|
+
// * --params "0x123...456" "0x789...abc"
|
|
36
|
+
// * ```
|
|
37
|
+
// */
|
|
38
|
+
// const commandModule: CommandModule<Options, Options> = {
|
|
39
|
+
// command: 'query',
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
// describe: 'Query dubhe schema struct state',
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
43
|
+
// builder: {
|
|
44
|
+
// network: {
|
|
45
|
+
// type: 'string',
|
|
46
|
+
// choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
|
|
47
|
+
// default: 'localnet',
|
|
48
|
+
// desc: 'Node network (mainnet/testnet/devnet/localnet)'
|
|
49
|
+
// },
|
|
50
|
+
// 'config-path': {
|
|
51
|
+
// type: 'string',
|
|
52
|
+
// default: 'dubhe.config.ts',
|
|
53
|
+
// desc: 'Configuration file path'
|
|
54
|
+
// },
|
|
55
|
+
// schema: {
|
|
56
|
+
// type: 'string',
|
|
57
|
+
// desc: 'Schema name',
|
|
58
|
+
// demandOption: true
|
|
59
|
+
// },
|
|
60
|
+
// 'object-id': {
|
|
61
|
+
// type: 'string',
|
|
62
|
+
// desc: 'Object ID (optional)'
|
|
63
|
+
// },
|
|
64
|
+
// 'package-id': {
|
|
65
|
+
// type: 'string',
|
|
66
|
+
// desc: 'Package ID (optional)'
|
|
67
|
+
// },
|
|
68
|
+
// 'metadata-path': {
|
|
69
|
+
// type: 'string',
|
|
70
|
+
// desc: 'Path to metadata JSON file (optional)'
|
|
71
|
+
// },
|
|
72
|
+
// params: {
|
|
73
|
+
// type: 'array',
|
|
74
|
+
// desc: 'Params for storage type: StorageValue(no params), StorageMap(1 param), StorageDoubleMap(2 params)',
|
|
75
|
+
// string: true
|
|
76
|
+
// }
|
|
77
|
+
// },
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
// async handler({
|
|
80
|
+
// network,
|
|
81
|
+
// 'config-path': configPath,
|
|
82
|
+
// schema,
|
|
83
|
+
// 'object-id': objectId,
|
|
84
|
+
// 'package-id': packageId,
|
|
85
|
+
// 'metadata-path': metadataPath,
|
|
86
|
+
// params
|
|
87
|
+
// }) {
|
|
88
|
+
// try {
|
|
89
|
+
// const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
};
|
|
91
|
+
// await queryStorage({
|
|
92
|
+
// dubheConfig,
|
|
93
|
+
// schema,
|
|
94
|
+
// objectId,
|
|
95
|
+
// network,
|
|
96
|
+
// packageId,
|
|
97
|
+
// metadataFilePath: metadataPath,
|
|
98
|
+
// params
|
|
99
|
+
// });
|
|
100
|
+
// } catch (error: any) {
|
|
101
|
+
// logError(error);
|
|
102
|
+
// process.exit(1);
|
|
103
|
+
// }
|
|
104
|
+
// process.exit(0);
|
|
105
|
+
// }
|
|
106
|
+
// };
|
|
107
107
|
|
|
108
|
-
export default commandModule;
|
|
108
|
+
// export default commandModule;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CommandModule } from 'yargs';
|
|
2
2
|
import { schemaGen, loadConfig, DubheConfig } from '@0xobelisk/sui-common';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
+
import path from "node:path";
|
|
4
5
|
|
|
5
6
|
type Options = {
|
|
6
7
|
'config-path'?: string;
|
|
@@ -27,8 +28,10 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
27
28
|
|
|
28
29
|
async handler({ 'config-path': configPath, network }) {
|
|
29
30
|
try {
|
|
31
|
+
if (!configPath) throw new Error('Config path is required');
|
|
30
32
|
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
31
|
-
|
|
33
|
+
const rootDir = path.dirname(configPath);
|
|
34
|
+
await schemaGen(rootDir, dubheConfig, network);
|
|
32
35
|
process.exit(0);
|
|
33
36
|
} catch (error: any) {
|
|
34
37
|
console.log(chalk.red('Schemagen failed!'));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CommandModule, ArgumentsCamelCase } from 'yargs';
|
|
2
|
+
import { switchEnv } from '../utils';
|
|
3
|
+
|
|
4
|
+
type Options = {
|
|
5
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const commandModule: CommandModule<Options, Options> = {
|
|
9
|
+
command: 'switch-env',
|
|
10
|
+
describe: 'Switch environment',
|
|
11
|
+
builder(yargs) {
|
|
12
|
+
return yargs.option('network', {
|
|
13
|
+
type: 'string',
|
|
14
|
+
choices: ['mainnet', 'testnet', 'devnet', 'localnet'] as const,
|
|
15
|
+
default: 'localnet',
|
|
16
|
+
desc: 'Switch to node network (mainnet/testnet/devnet/localnet)'
|
|
17
|
+
}) as any;
|
|
18
|
+
},
|
|
19
|
+
async handler(argv: ArgumentsCamelCase<Options>) {
|
|
20
|
+
await switchEnv(argv.network as 'mainnet' | 'testnet' | 'devnet' | 'localnet');
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default commandModule;
|
package/src/commands/test.ts
CHANGED
|
@@ -38,7 +38,7 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
38
38
|
console.log('🚀 Running move test');
|
|
39
39
|
const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
40
40
|
const path = process.cwd();
|
|
41
|
-
const projectPath = `${path}/
|
|
41
|
+
const projectPath = `${path}/src/${dubheConfig.name}`;
|
|
42
42
|
const command = `sui move test --path ${projectPath} ${
|
|
43
43
|
test ? ` --test ${test}` : ''
|
|
44
44
|
} --gas-limit ${gasLimit}`;
|
package/src/commands/upgrade.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import type { CommandModule } from 'yargs';
|
|
2
|
-
import { logError } from '../utils/errors';
|
|
3
|
-
import { upgradeHandler } from '../utils/upgradeHandler';
|
|
4
|
-
import { DubheConfig, loadConfig } from '@0xobelisk/sui-common';
|
|
1
|
+
// import type { CommandModule } from 'yargs';
|
|
2
|
+
// import { logError } from '../utils/errors';
|
|
3
|
+
// import { upgradeHandler } from '../utils/upgradeHandler';
|
|
4
|
+
// import { DubheConfig, loadConfig } from '@0xobelisk/sui-common';
|
|
5
5
|
|
|
6
|
-
type Options = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
6
|
+
// type Options = {
|
|
7
|
+
// network: any;
|
|
8
|
+
// 'config-path': string;
|
|
9
|
+
// };
|
|
10
10
|
|
|
11
|
-
const commandModule: CommandModule<Options, Options> = {
|
|
12
|
-
|
|
11
|
+
// const commandModule: CommandModule<Options, Options> = {
|
|
12
|
+
// command: 'upgrade',
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
// describe: 'Upgrade your move contracts',
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
// builder(yargs) {
|
|
17
|
+
// return yargs.options({
|
|
18
|
+
// network: {
|
|
19
|
+
// type: 'string',
|
|
20
|
+
// choices: ['mainnet', 'testnet', 'devnet', 'localnet'],
|
|
21
|
+
// default: 'localnet',
|
|
22
|
+
// desc: 'Network of the node (mainnet/testnet/devnet/localnet)'
|
|
23
|
+
// },
|
|
24
|
+
// 'config-path': {
|
|
25
|
+
// type: 'string',
|
|
26
|
+
// default: 'dubhe.config.ts',
|
|
27
|
+
// decs: 'Path to the config file'
|
|
28
|
+
// }
|
|
29
|
+
// });
|
|
30
|
+
// },
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
32
|
+
// async handler({ network, 'config-path': configPath }) {
|
|
33
|
+
// try {
|
|
34
|
+
// const dubheConfig = (await loadConfig(configPath)) as DubheConfig;
|
|
35
|
+
// await upgradeHandler(dubheConfig, dubheConfig.name, network);
|
|
36
|
+
// } catch (error: any) {
|
|
37
|
+
// logError(error);
|
|
38
|
+
// process.exit(1);
|
|
39
|
+
// }
|
|
40
|
+
// process.exit(0);
|
|
41
|
+
// }
|
|
42
|
+
// };
|
|
43
43
|
|
|
44
|
-
export default commandModule;
|
|
44
|
+
// export default commandModule;
|
package/src/dubhe.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import yargs from 'yargs';
|
|
4
4
|
import { hideBin } from 'yargs/helpers';
|
|
5
|
+
import chalk from 'chalk';
|
|
5
6
|
import { commands } from './commands';
|
|
6
7
|
import { logError } from './utils/errors';
|
|
8
|
+
import packageJson from '../package.json';
|
|
7
9
|
|
|
8
10
|
// Load .env file into process.env
|
|
9
11
|
import * as dotenv from 'dotenv';
|
|
10
|
-
import chalk from 'chalk';
|
|
11
12
|
dotenv.config();
|
|
12
13
|
|
|
13
14
|
yargs(hideBin(process.argv))
|
|
@@ -16,11 +17,15 @@ yargs(hideBin(process.argv))
|
|
|
16
17
|
// Use the commands directory to scaffold
|
|
17
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- command array overload isn't typed, see https://github.com/yargs/yargs/blob/main/docs/advanced.md#esm-hierarchy
|
|
18
19
|
.command(commands as any)
|
|
20
|
+
.version(packageJson.version)
|
|
21
|
+
.demandCommand(1, 'Please provide a command')
|
|
22
|
+
.recommendCommands()
|
|
19
23
|
// Enable strict mode.
|
|
20
24
|
.strict()
|
|
21
25
|
// Custom error handler
|
|
22
26
|
.fail((msg, err) => {
|
|
23
27
|
console.error(chalk.red(msg));
|
|
28
|
+
|
|
24
29
|
if (msg.includes('Missing required argument')) {
|
|
25
30
|
console.log(
|
|
26
31
|
chalk.yellow(
|
|
@@ -29,8 +34,11 @@ yargs(hideBin(process.argv))
|
|
|
29
34
|
);
|
|
30
35
|
}
|
|
31
36
|
console.log('');
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
// Even though `.fail` type says we should get an `Error`, this can sometimes be undefined
|
|
38
|
+
if (err != null) {
|
|
39
|
+
logError(err);
|
|
40
|
+
console.log('');
|
|
41
|
+
}
|
|
34
42
|
|
|
35
43
|
process.exit(1);
|
|
36
44
|
})
|