Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit 73f7038

Browse files
committed
[update] change tab auto completion and fix data report
1 parent 7beea19 commit 73f7038

16 files changed

Lines changed: 93 additions & 100 deletions

File tree

bin/cloudbase.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ const Sentry = require('@sentry/node')
88
const logSymbols = require('log-symbols')
99
const didYouMean = require('didyoumean')
1010
const updateNotifier = require('update-notifier')
11+
const omelette = require('omelette')
1112

1213
const pkg = require('../package.json')
1314
const store = require('../lib/utils/store')
1415
const { ALL_COMMANDS } = require('../lib/constant')
1516
const { getProxy } = require('../lib/utils/tools/proxy')
1617
const { handleCompletion } = require('../lib/completion')
1718

19+
const completion = omelette('cloudbase|tcb <action>')
20+
completion.on('action', handleCompletion)
21+
completion.init()
22+
1823
let processArgv = process.argv
1924
const isBeta = pkg.version.indexOf('-') > -1
2025
process.CLI_VERSION = pkg.version

lib/commands/command.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1111
var __importDefault = (this && this.__importDefault) || function (mod) {
1212
return (mod && mod.__esModule) ? mod : { "default": mod };
1313
};
14+
var __importStar = (this && this.__importStar) || function (mod) {
15+
if (mod && mod.__esModule) return mod;
16+
var result = {};
17+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
18+
result["default"] = mod;
19+
return result;
20+
};
1421
Object.defineProperty(exports, "__esModule", { value: true });
1522
const chalk_1 = __importDefault(require("chalk"));
1623
const commander_1 = __importDefault(require("commander"));
17-
const node_1 = __importDefault(require("@sentry/node"));
24+
const Sentry = __importStar(require("@sentry/node"));
1825
const events_1 = require("events");
1926
const error_1 = require("../error");
2027
const utils_1 = require("../utils");
@@ -64,8 +71,8 @@ class Command extends events_1.EventEmitter {
6471
}
6572
preHandle() {
6673
return __awaiter(this, void 0, void 0, function* () {
74+
const loading = utils_1.loadingFactory();
6775
try {
68-
const loading = utils_1.loadingFactory();
6976
loading.start('数据加载中...');
7077
const res = yield utils_1.getNotification();
7178
loading.stop();
@@ -76,7 +83,8 @@ class Command extends events_1.EventEmitter {
7683
console.log(content, '\n');
7784
}
7885
catch (e) {
79-
node_1.default.captureException(e);
86+
loading.stop();
87+
Sentry.captureException(e);
8088
}
8189
});
8290
}
@@ -90,7 +98,7 @@ class Command extends events_1.EventEmitter {
9098
yield utils_1.collectUsage(cmd);
9199
}
92100
catch (e) {
93-
node_1.default.captureException(e);
101+
Sentry.captureException(e);
94102
}
95103
});
96104
}

lib/commands/completion/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ const command_1 = require("../command");
44
const tab_1 = require("./tab");
55
const commands = [
66
{
7-
cmd: 'completion:install',
7+
cmd: 'completion:setup',
88
options: [],
9-
desc: '安装自动补全',
9+
desc: '启动自动补全命令',
1010
handler: tab_1.installCompletion,
1111
requiredEnvId: false
1212
},
1313
{
14-
cmd: 'completion:uninstall',
14+
cmd: 'completion:clean',
1515
options: [],
16-
desc: '登出腾讯云账号',
16+
desc: '清楚自动补全命令',
1717
handler: tab_1.unInstallCompletion,
1818
requiredEnvId: false
1919
}

lib/commands/completion/tab.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1212
return (mod && mod.__esModule) ? mod : { "default": mod };
1313
};
1414
Object.defineProperty(exports, "__esModule", { value: true });
15-
const tabtab_1 = __importDefault(require("tabtab"));
15+
const omelette_1 = __importDefault(require("omelette"));
1616
const error_1 = require("../../error");
17+
const logger_1 = require("../../logger");
18+
const completion = omelette_1.default('cloudbase|tcb <action>');
1719
function installCompletion() {
1820
return __awaiter(this, void 0, void 0, function* () {
1921
try {
20-
yield tabtab_1.default.install({
21-
name: 'tcb',
22-
completer: 'tcb'
22+
process.on('exit', () => {
23+
logger_1.successLog('安装完成,重启终端后生效!');
2324
});
25+
completion.setupShellInitFile();
2426
}
2527
catch (e) {
2628
throw new error_1.CloudBaseError('安装失败!');
@@ -31,10 +33,10 @@ exports.installCompletion = installCompletion;
3133
function unInstallCompletion() {
3234
return __awaiter(this, void 0, void 0, function* () {
3335
try {
34-
yield tabtab_1.default.uninstall({
35-
name: 'tcb',
36-
completer: 'tcb'
36+
process.on('exit', () => {
37+
logger_1.successLog('卸载完成,重启终端后生效!');
3738
});
39+
completion.cleanupShellInitFile();
3840
}
3941
catch (e) {
4042
throw new error_1.CloudBaseError('卸载失败!');

lib/commands/env/create.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ function create(ctx, alias) {
4848
message: '请选择环境计费模式:',
4949
default: 'postpay'
5050
});
51+
const { confirm } = yield inquirer_1.default.prompt({
52+
type: 'confirm',
53+
name: 'confirm',
54+
message: '因支付权限问题,仅支持通过 API 秘钥登陆的主账户使用 CLI 创建包年包月免费环境,其他用户需要登陆控制台支付相关订单才能完成环境创建,是否继续?',
55+
default: false
56+
});
57+
if (!confirm) {
58+
throw new error_1.CloudBaseError('创建环境流程终止');
59+
}
5160
loading.start('环境创建中...');
5261
try {
5362
const res = yield env_1.createEnv({

lib/completion/index.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
"use strict";
2-
var __importDefault = (this && this.__importDefault) || function (mod) {
3-
return (mod && mod.__esModule) ? mod : { "default": mod };
4-
};
52
Object.defineProperty(exports, "__esModule", { value: true });
6-
const tabtab_1 = __importDefault(require("tabtab"));
73
const constant_1 = require("../constant");
8-
const completion = env => {
9-
if (!env.complete)
10-
return;
11-
const args = process.argv.slice(5);
12-
const cmd = args[0];
4+
function handleCompletion({ reply, line }) {
5+
const cmd = line.replace(/^cloudbase\s|^tcb\s/, '');
136
const commands = constant_1.ALL_COMMANDS.filter(item => item.indexOf(cmd) > -1);
147
if (commands.length > 0) {
15-
return tabtab_1.default.log(commands);
8+
reply(commands);
169
}
1710
else {
18-
return tabtab_1.default.log(['-h', '-v']);
11+
reply(['-h', '-v']);
1912
}
20-
};
21-
function handleCompletion() {
22-
const env = tabtab_1.default.parseEnv(process.env);
23-
completion(env);
2413
}
2514
exports.handleCompletion = handleCompletion;

lib/constant.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ exports.ALL_COMMANDS = [
2121
'logout',
2222
'init',
2323
'open',
24-
'completion:install',
25-
'completion:uninstall',
24+
'completion:setup',
25+
'completion:clean',
2626
'env:list',
2727
'env:rename',
2828
'env:create',

package-lock.json

Lines changed: 5 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
"make-dir": "^3.0.0",
4646
"node-fetch": "^2.6.0",
4747
"node-ssh": "^6.0.0",
48+
"omelette": "^0.4.12",
4849
"open": "^7.0.0",
4950
"ora": "^4.0.2",
5051
"portfinder": "^1.0.20",
5152
"progress": "^2.0.3",
5253
"query-string": "^6.8.1",
53-
"tabtab": "^3.0.2",
5454
"tar-fs": "^2.0.0",
5555
"terminal-link": "^2.1.1",
5656
"unzipper": "^0.10.5",

src/commands/command.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-dupe-class-members */
22
import chalk from 'chalk'
33
import program from 'commander'
4-
import Sentry from '@sentry/node'
4+
import * as Sentry from '@sentry/node'
55
import { EventEmitter } from 'events'
66
import { CloudBaseError } from '../error'
77
import { ICloudBaseConfig } from '../types'
@@ -99,8 +99,8 @@ export class Command extends EventEmitter {
9999
}
100100

101101
private async preHandle() {
102+
const loading = loadingFactory()
102103
try {
103-
const loading = loadingFactory()
104104
loading.start('数据加载中...')
105105
const res = await getNotification()
106106
loading.stop()
@@ -109,6 +109,7 @@ export class Command extends EventEmitter {
109109
console.log(chalk.bold.cyan(title))
110110
console.log(content, '\n')
111111
} catch (e) {
112+
loading.stop()
112113
Sentry.captureException(e)
113114
}
114115
}

0 commit comments

Comments
 (0)