@@ -80,22 +80,27 @@ export default class CipQuery extends CipCommand<typeof CipQuery> {
8080
8181 private resolveSql ( ) : string {
8282 const positionalSql = this . args . sql ;
83- const sources = [ Boolean ( positionalSql ) , Boolean ( this . flags . file ) , Boolean ( this . flags . stdin ) ] . filter (
84- Boolean ,
85- ) . length ;
83+ const hasPositional = Boolean ( positionalSql ) ;
84+ const hasFile = Boolean ( this . flags . file ) ;
85+ const hasStdin = this . flags . stdin === true ;
8686
87- if ( sources === 0 ) {
88- this . error ( 'No SQL provided. Pass SQL as an argument, or use --file / --stdin.' ) ;
87+ if ( hasStdin && hasFile ) {
88+ this . error ( 'Use either --stdin or --file, not both.' ) ;
89+ }
90+
91+ if ( ! hasStdin && hasFile && hasPositional ) {
92+ this . error ( 'Use either a positional SQL argument or --file, not both.' ) ;
8993 }
9094
91- if ( sources > 1 ) {
92- this . error ( 'Provide SQL from exactly one source: positional argument, --file, or --stdin.' ) ;
95+ if ( ! hasStdin && ! hasFile && ! hasPositional ) {
96+ this . error ( 'No SQL provided. Pass SQL as an argument, or use --file / --stdin.' ) ;
9397 }
9498
95- const rawSql =
96- positionalSql ??
97- ( this . flags . file ? fs . readFileSync ( this . flags . file , 'utf8' ) : undefined ) ??
98- ( this . flags . stdin ? fs . readFileSync ( 0 , 'utf8' ) : undefined ) ;
99+ const rawSql = hasStdin
100+ ? fs . readFileSync ( 0 , 'utf8' )
101+ : hasFile
102+ ? fs . readFileSync ( this . flags . file as string , 'utf8' )
103+ : positionalSql ;
99104
100105 if ( ! rawSql || rawSql . trim ( ) . length === 0 ) {
101106 this . error ( 'SQL input is empty.' ) ;
0 commit comments