@@ -52,13 +52,8 @@ abstract class NyCustomCommand {
5252 /// Run a process with the given command
5353 runProcess (String command,
5454 {String ? workingDirectory, bool ? runInShell, bool silent = false }) async {
55- if (silent == false ) {
56- // Print the command being run
57- print ('Running command: $command ' );
58- }
59-
60- // Split the command into parts
61- final List <String > parts = command.split (' ' );
55+ // Parse command properly handling quotes
56+ final List <String > parts = _parseCommand (command);
6257 final String executable = parts[0 ];
6358 final List <String > args = parts.sublist (1 );
6459
@@ -90,16 +85,50 @@ abstract class NyCustomCommand {
9085 if (exitCode != 0 ) {
9186 // Print an error message if the process failed
9287 error ('Command failed with exit code: $exitCode ' );
93- } else {
94- // Print a success message if the process succeeded
95- success ('Command completed successfully.' );
9688 }
9789 }
9890
9991 // Return the exit code
10092 return exitCode;
10193 }
10294
95+ // Helper method to parse command strings correctly handling quotes
96+ List <String > _parseCommand (String command) {
97+ final List <String > parts = [];
98+ bool inQuotes = false ;
99+ String currentPart = '' ;
100+ String quoteChar = '' ;
101+
102+ for (int i = 0 ; i < command.length; i++ ) {
103+ final char = command[i];
104+
105+ if ((char == '"' || char == "'" ) && (i == 0 || command[i - 1 ] != '\\ ' )) {
106+ if (! inQuotes) {
107+ inQuotes = true ;
108+ quoteChar = char;
109+ } else if (char == quoteChar) {
110+ inQuotes = false ;
111+ quoteChar = '' ;
112+ } else {
113+ currentPart += char;
114+ }
115+ } else if (char == ' ' && ! inQuotes) {
116+ if (currentPart.isNotEmpty) {
117+ parts.add (currentPart);
118+ currentPart = '' ;
119+ }
120+ } else {
121+ currentPart += char;
122+ }
123+ }
124+
125+ if (currentPart.isNotEmpty) {
126+ parts.add (currentPart);
127+ }
128+
129+ return parts;
130+ }
131+
103132 /// Add a package to the pubspec.yaml file
104133 addPackage (String package, {String ? version, bool dev = false }) async {
105134 await MetroService .addPackage (package, dev: dev, version: version);
0 commit comments