@@ -36,15 +36,10 @@ export default class CipQuery extends CipCommand<typeof CipQuery> {
3636 description : 'Read SQL query from file' ,
3737 helpGroup : 'QUERY' ,
3838 } ) ,
39- stdin : Flags . boolean ( {
40- description : 'Read SQL query from stdin' ,
41- default : false ,
42- helpGroup : 'QUERY' ,
43- } ) ,
4439 } ;
4540
4641 async run ( ) : Promise < CipQueryCommandResult > {
47- const sql = await this . resolveSql ( ) ;
42+ const sql = this . resolveSql ( ) ;
4843
4944 this . requireCipCredentials ( ) ;
5045 const client = this . getCipClient ( ) ;
@@ -69,21 +64,6 @@ export default class CipQuery extends CipCommand<typeof CipQuery> {
6964 return output ;
7065 }
7166
72- private async readSqlFromStdin ( ) : Promise < string > {
73- const preBufferedInput = process . env . SFCC_CIP_QUERY_STDIN ;
74- if ( preBufferedInput !== undefined ) {
75- return preBufferedInput ;
76- }
77-
78- let data = '' ;
79-
80- for await ( const chunk of process . stdin ) {
81- data += typeof chunk === 'string' ? chunk : chunk . toString ( 'utf8' ) ;
82- }
83-
84- return data ;
85- }
86-
8767 private renderRows ( columns : string [ ] , rows : Array < Record < string , unknown > > , format : CipOutputFormat ) : void {
8868 if ( format === 'csv' ) {
8969 process . stdout . write ( `${ toCsv ( columns , rows ) } \n` ) ;
@@ -93,29 +73,21 @@ export default class CipQuery extends CipCommand<typeof CipQuery> {
9373 renderTable ( columns , rows ) ;
9474 }
9575
96- private async resolveSql ( ) : Promise < string > {
76+ private resolveSql ( ) : string {
9777 const positionalSql = this . args . sql ;
9878 const hasPositional = Boolean ( positionalSql ) ;
9979 const hasFile = Boolean ( this . flags . file ) ;
100- const hasStdin = this . flags . stdin === true ;
101-
102- if ( hasStdin && hasFile ) {
103- this . error ( 'Use either --stdin or --file, not both.' ) ;
104- }
80+ const sourceCount = [ hasPositional , hasFile ] . filter ( Boolean ) . length ;
10581
106- if ( ! hasStdin && hasFile && hasPositional ) {
107- this . error ( 'Use either a positional SQL argument or --file, not both .' ) ;
82+ if ( sourceCount === 0 ) {
83+ this . error ( 'No SQL provided. Pass SQL as an argument, pipe SQL through stdin, or use --file.' ) ;
10884 }
10985
110- if ( ! hasStdin && ! hasFile && ! hasPositional ) {
111- this . error ( 'No SQL provided. Pass SQL as an argument, or use --file / --stdin .' ) ;
86+ if ( sourceCount > 1 ) {
87+ this . error ( 'Provide SQL from exactly one source: positional argument/stdin , or --file.' ) ;
11288 }
11389
114- const rawSql = hasStdin
115- ? await this . readSqlFromStdin ( )
116- : hasFile
117- ? fs . readFileSync ( this . flags . file as string , 'utf8' )
118- : positionalSql ;
90+ const rawSql = hasFile ? fs . readFileSync ( this . flags . file as string , 'utf8' ) : positionalSql ;
11991
12092 if ( ! rawSql || rawSql . trim ( ) . length === 0 ) {
12193 this . error ( 'SQL input is empty.' ) ;
0 commit comments