@@ -56,7 +56,6 @@ const argv = yargs(hideBin(process.argv))
5656 } ) ;
5757 } ,
5858 async ( argv ) => {
59- console . log ( `Reading file: ${ argv . file } ` ) ;
6059 if ( argv . file . toLowerCase ( ) . endsWith ( `.flow` ) ) {
6160 let content = undefined ;
6261 try {
@@ -79,9 +78,9 @@ const argv = yargs(hideBin(process.argv))
7978 argv . env ? getEnvVariables ( argv . env ) : { } ,
8079 logger ,
8180 ) ;
82- console . log ( chalk . yellow ( 'Running Flow \n' ) ) ;
81+ console . log ( chalk . blue ( 'Running Flow \n' ) ) ;
8382 console . log (
84- chalk . blue (
83+ chalk . yellow (
8584 'Right now CLI commands must be run from root directory of collection. We will gradually add support to run commands from anywhere inside the collection. \n' ,
8685 ) ,
8786 ) ;
@@ -109,27 +108,43 @@ const argv = yargs(hideBin(process.argv))
109108 } ;
110109 const accessId = process . env . FLOWTEST_ACCESS_ID ;
111110 const accessKey = process . env . FLOWTEST_ACCESS_KEY ;
112- try {
113- const response = await axiosClient . post ( '/upload' , data , {
114- headers : {
115- 'Content-Type' : 'application/json' ,
116- 'x-access-id' : accessId ,
117- 'x-access-key' : accessKey ,
118- } ,
119- } ) ;
120- console . log ( chalk . bold ( 'Flow Scan: ' ) + chalk . dim ( `${ baseUrl } /scan/${ response . data . data [ 0 ] . id } ` ) ) ;
121- } catch ( error ) {
122- if ( error ?. response ) {
123- if ( error . response ?. status >= 400 && error . response ?. status < 500 ) {
124- console . log ( chalk . red ( ` ${ JSON . stringify ( error . response ?. data ) } ` ) ) ;
125- }
111+ if ( ! accessId || accessId . trim ( ) === '' || ! accessKey || accessKey . trim ( ) === '' ) {
112+ console . log ( chalk . red ( ` ✕ ` ) + chalk . dim ( 'Unable to upload flow scan' ) ) ;
113+ console . log (
114+ chalk . yellow ( `Failed to detect access key pairs. Make sure to set environment variables properly.` ) ,
115+ ) ;
116+ console . log ( chalk . yellow ( ` export FLOWTEST_ACCESS_ID="<<FLOWTEST_ACCESS_ID>>"` ) ) ;
117+ console . log ( chalk . yellow ( ` export FLOWTEST_ACCESS_KEY="<<FLOWTEST_ACCESS_KEY>>"` ) ) ;
118+ } else {
119+ try {
120+ const response = await axiosClient . post ( '/upload' , data , {
121+ headers : {
122+ 'Content-Type' : 'application/json' ,
123+ 'x-access-id' : accessId ,
124+ 'x-access-key' : accessKey ,
125+ } ,
126+ } ) ;
127+ console . log ( chalk . bold ( 'Flow Scan: ' ) + chalk . dim ( `${ baseUrl } /scan/${ response . data . data [ 0 ] . id } ` ) ) ;
128+ } catch ( error ) {
129+ if ( error ?. response ) {
130+ if ( error . response ?. status >= 400 && error . response ?. status < 500 ) {
131+ console . log ( chalk . red ( ` ${ JSON . stringify ( error . response ?. data ) } ` ) ) ;
132+ }
126133
127- if ( error . response ?. status === 500 ) {
128- console . log ( chalk . red ( ' Internal Server Error' ) ) ;
134+ if ( error . response ?. status === 500 ) {
135+ console . log ( chalk . red ( ' Internal Server Error' ) ) ;
136+ }
129137 }
138+ console . log ( chalk . red ( ` ✕ ` ) + chalk . dim ( 'Unable to upload flow scan' ) ) ;
130139 }
131- console . log ( chalk . red ( ` ✕ ` ) + chalk . dim ( 'Unable to upload flow scan' ) ) ;
132140 }
141+ } else {
142+ console . log ( '\n' ) ;
143+ console . log (
144+ chalk . yellow (
145+ 'Enable flow scans today to get more value our of your APIs. Get your access key pairs at https://flowtest-ai.vercel.app/ \n' ,
146+ ) ,
147+ ) ;
133148 }
134149
135150 process . exit ( 1 ) ;
0 commit comments