11import { Command } from 'commander' ;
22import chalk from 'chalk' ;
33import * 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' ;
66import logger from '@/logger' ;
77import path from 'path' ;
88import 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