@@ -112,6 +112,41 @@ function parseCommands(content) {
112112 . filter ( line => line && ! line . startsWith ( '#' ) ) ;
113113}
114114
115+ // Parse command arguments to properly identify flags regardless of position
116+ function parseCommandArgs ( commandLine ) {
117+ // Split by spaces but preserve quoted strings
118+ const regex = / [ ^ \s " ' ] + | " ( [ ^ " ] * ) " | ' ( [ ^ ' ] * ) ' / g;
119+ let matches = [ ] ;
120+ let match ;
121+
122+ while ( ( match = regex . exec ( commandLine ) ) ) {
123+ // If the match is a quoted string, use the captured group
124+ if ( match [ 1 ] || match [ 2 ] ) {
125+ matches . push ( match [ 1 ] || match [ 2 ] ) ;
126+ } else {
127+ matches . push ( match [ 0 ] ) ;
128+ }
129+ }
130+
131+ // Separate command, flags, and other arguments
132+ const command = matches [ 0 ] ;
133+ const flags = matches . filter ( arg => arg . startsWith ( '--' ) ) ;
134+ const nonFlagArgs = matches . filter ( arg => ! arg . startsWith ( '--' ) && arg !== command ) ;
135+
136+ return {
137+ command,
138+ flags,
139+ nonFlagArgs,
140+ allArgs : [ ...nonFlagArgs , ...flags ]
141+ } ;
142+ }
143+
144+ // Check if a command has a specific flag
145+ function hasFlag ( commandLine , flagName ) {
146+ const { flags } = parseCommandArgs ( commandLine ) ;
147+ return flags . includes ( flagName ) ;
148+ }
149+
115150// Get command type from full command
116151function getCommandType ( command ) {
117152 const parts = command . split ( ' ' ) ;
@@ -221,17 +256,38 @@ async function executeCommands(commands) {
221256 try {
222257 // Handle redirection separately if present
223258 const hasRedirection = command . includes ( '>' ) ;
224- const actualCommand = hasRedirection ? command . split ( '>' ) [ 0 ] . trim ( ) : command ;
259+ const commandToProcess = hasRedirection ? command . split ( '>' ) [ 0 ] . trim ( ) : command ;
225260 const redirectTarget = hasRedirection ? command . split ( '>' ) [ 1 ] . trim ( ) : null ;
226261
262+ // Parse the command arguments to properly handle flags
263+ const parsedCommand = parseCommandArgs ( commandToProcess ) ;
264+ const cmdType = parsedCommand . command ;
265+
227266 // Create a unique output file for this command
228267 const outputFile = path . join ( tmpDir , `cmd_${ i } .out` ) ;
229268
230269 // Set maximum buffer size based on command type
231- const cmdType = getCommandType ( actualCommand ) ;
232270 const maxBuffer = cmdType === 'list' ? 5 * 1024 * 1024 : 1024 * 1024 ; // 5MB for list, 1MB for others
233271
234- const result = execSync ( `${ TASKTRACKER_BIN } ${ actualCommand } --non-interactive` , {
272+ // Build the command with proper flag handling
273+ let execCommand = `${ TASKTRACKER_BIN } ${ parsedCommand . command } ` ;
274+
275+ // Add non-flag arguments first
276+ if ( parsedCommand . nonFlagArgs . length > 0 ) {
277+ execCommand += ` ${ parsedCommand . nonFlagArgs . join ( ' ' ) } ` ;
278+ }
279+
280+ // Add flags
281+ if ( parsedCommand . flags . length > 0 ) {
282+ execCommand += ` ${ parsedCommand . flags . join ( ' ' ) } ` ;
283+ }
284+
285+ // Always add non-interactive flag for batch operations
286+ if ( ! parsedCommand . flags . includes ( '--non-interactive' ) ) {
287+ execCommand += ' --non-interactive' ;
288+ }
289+
290+ const result = execSync ( execCommand , {
235291 encoding : 'utf8' ,
236292 stdio : [ 'pipe' , 'pipe' , 'pipe' ] ,
237293 maxBuffer : maxBuffer
0 commit comments