Skip to content

Commit 36e17be

Browse files
committed
fix: cli dont support --output-format
Signed-off-by: zxypro1 <1018995004@qq.com>
1 parent 3bba199 commit 36e17be

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

src/command/cli/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Command } from 'commander';
22
import chalk from 'chalk';
3-
import { emoji, getUid, isJson, writeOutput } from '@/utils';
3+
import { emoji, getUid, isJson, showOutput, writeOutput } from '@/utils';
44
import * as utils from '@serverless-devs/utils';
55
import loadComponent from '@serverless-devs/load-component';
66
import Credential from '@serverless-devs/credential';
7-
import { each, filter, get, includes, isString } from 'lodash';
7+
import { each, filter, get, includes } from 'lodash';
88
import logger from '@/logger';
99
import Help from './help';
1010
import execDaemon from '@/exec-daemon';
@@ -102,14 +102,10 @@ const doAction = async () => {
102102
const reportData = { uid: await getUid(access), argv, command, component: componentName, userAgent: getUserAgent({ component: componentName }) };
103103
try {
104104
const res = await instance[command](inputs);
105-
const showOutput = () => {
106-
if (rest['output-file']) return;
107-
logger.unsilent();
108-
isString(res) ? (silent ? logger.write(res) : logger.write(chalk.green(res))) : logger.output(res);
109-
if (silent) logger.silent();
110-
};
111-
showOutput();
112-
writeOutput(res);
105+
const argv = process.argv.slice(2);
106+
const argvData = utils.parseArgv(argv);
107+
const outputFile = get(argvData, 'output-file');
108+
outputFile ? writeOutput(res) : showOutput(res);
113109
execDaemon('report.js', { ...reportData, type: EReportType.command });
114110
return;
115111
} catch (error) {

src/command/cli/v1.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Command } from 'commander';
22
import chalk from 'chalk';
33
import * as core from '@serverless-devs/core';
4-
import { emoji, getUid, writeOutput } from '@/utils';
5-
import { includes, isEmpty, isPlainObject, isString } from 'lodash';
4+
import { emoji, getUid, showOutput, writeOutput } from '@/utils';
5+
import { get, includes, isEmpty, isPlainObject } from 'lodash';
66
import logger from '@/logger';
77
import path from 'path';
88
import execDaemon from '@/exec-daemon';
@@ -18,7 +18,7 @@ const v1 = (program: Command) => {
1818
const doAction = async options => {
1919
const argv = process.argv.slice(2);
2020
const argvData = core.getGlobalArgs(argv);
21-
const { _: rawData, access = 'default', help, silent } = argvData;
21+
const { _: rawData, access = 'default', help } = argvData;
2222
// s cli
2323
if (rawData.length === 1 || (rawData.length === 1 && help)) {
2424
program.help();
@@ -69,15 +69,10 @@ const v1 = (program: Command) => {
6969
if (isEmpty(res)) {
7070
return logger.write(chalk.green(`End of method: ${_method}`));
7171
}
72-
const showOutput = () => {
73-
const argv = parseArgv(process.argv.slice(2));
74-
if (argv['output-file']) return;
75-
logger.unsilent();
76-
isString(res) ? (silent ? logger.write(res) : logger.write(chalk.green(res))) : logger.output(res);
77-
if (silent) logger.silent();
78-
};
79-
showOutput();
80-
writeOutput(res);
72+
const argv = process.argv.slice(2);
73+
const argvData = parseArgv(argv);
74+
const outputFile = get(argvData, 'output-file');
75+
outputFile ? writeOutput(res) : showOutput(res);
8176
execDaemon('report.js', { ...reportData, type: EReportType.command });
8277
} catch (error) {
8378
handleError(

0 commit comments

Comments
 (0)