|
1 | 1 | import program from 'commander' |
2 | | -import ora from 'ora' |
3 | | -import { listEnvs, createEnv, getEnvInfo } from '../../env' |
4 | | -import { printCliTable } from '../../utils' |
| 2 | +import { listEnvs, createEnv, getEnvInfo, updateEnvInfo } from '../../env' |
| 3 | +import { printCliTable, loading, getEnvId } from '../../utils' |
5 | 4 | import { CloudBaseError } from '../../error' |
6 | | -import { successLog, warnLog } from '../../logger' |
| 5 | +import { warnLog, successLog } from '../../logger' |
7 | 6 |
|
8 | 7 | import './domain' |
9 | 8 | import './login' |
@@ -71,21 +70,44 @@ program |
71 | 70 | throw new CloudBaseError('环境名称不能为空!') |
72 | 71 | } |
73 | 72 |
|
| 73 | + loading.start('创建环境中') |
| 74 | + |
74 | 75 | const res = await createEnv({ |
75 | 76 | alias |
76 | 77 | }) |
77 | 78 |
|
| 79 | + loading.succeed('创建环境成功!') |
| 80 | + loading.start('环境初始化中') |
| 81 | + |
78 | 82 | if (res.Status === 'NORMAL') { |
79 | | - successLog('创建环境成功!') |
| 83 | + loading.start('环境初始化成功') |
80 | 84 | return |
81 | 85 | } |
82 | 86 |
|
83 | 87 | // 检查环境是否初始化成功 |
84 | | - const initSpinner = ora('环境初始化中...').start() |
85 | 88 | try { |
86 | 89 | await checkEnvAvailability(res.EnvId) |
87 | | - initSpinner.succeed('环境初始化成功') |
| 90 | + loading.succeed('环境初始化成功') |
88 | 91 | } catch (e) { |
89 | | - initSpinner.fail(e.message) |
| 92 | + loading.fail(e.message) |
90 | 93 | } |
91 | 94 | }) |
| 95 | + |
| 96 | +program |
| 97 | + .command('env:rename <name> [envId]') |
| 98 | + .description('重命名环境') |
| 99 | + .action(async function(name: string, envId: string, options) { |
| 100 | + if (!name) { |
| 101 | + throw new CloudBaseError('环境名称不能为空!') |
| 102 | + } |
| 103 | + |
| 104 | + const { configFile } = options.parent |
| 105 | + const assignEnvId = await getEnvId(envId, configFile) |
| 106 | + |
| 107 | + await updateEnvInfo({ |
| 108 | + envId: assignEnvId, |
| 109 | + alias: name |
| 110 | + }) |
| 111 | + |
| 112 | + successLog('更新环境名成功 !') |
| 113 | + }) |
0 commit comments