From f5dfdb93dee8eea4e7a46e0c87bffda309bf694e Mon Sep 17 00:00:00 2001
From: Moncef STITI <moncef.stiti@etu.u-pec.fr>
Date: Sun, 16 Mar 2025 17:36:39 +0100
Subject: [PATCH] Correction de bug #3

---
 .../monlouyan/bakefile/CommandExecutor.java   | 42 ++++++++++++++-----
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/src/fr/monlouyan/bakefile/CommandExecutor.java b/src/fr/monlouyan/bakefile/CommandExecutor.java
index 95b41c4..4a1e565 100644
--- a/src/fr/monlouyan/bakefile/CommandExecutor.java
+++ b/src/fr/monlouyan/bakefile/CommandExecutor.java
@@ -95,16 +95,24 @@ public class CommandExecutor {
 					boolean isFirstLine = true;
 					for (String line : displayLines) {
 						if (isFirstLine) {
-							// Pour la première ligne, supprimer l'indentation
+							// Pour la première ligne, supprimer l'indentation et le tiret si présent
+							String displayLine = line;
+							if (displayLine.startsWith("\t")) {
+								displayLine = displayLine.substring(1);
+							}
+							// Supprimer le tiret d'ignore-errors si présent
+							if (ignoreErrors && displayLine.trim().startsWith("-")) {
+								displayLine = displayLine.replaceFirst("\\s*-\\s*", " ").trim();
+							}
+							System.out.println(displayLine);
+							isFirstLine = false;
+						} else {
+							// Pour les lignes suivantes, également supprimer l'indentation
 							if (line.startsWith("\t")) {
 								System.out.println(line.substring(1));
 							} else {
 								System.out.println(line);
 							}
-							isFirstLine = false;
-						} else {
-							// Pour les lignes suivantes, conserver l'indentation
-							System.out.println(line);
 						}
 					}
 				}
@@ -116,6 +124,11 @@ public class CommandExecutor {
                     if(!isCircular && !silent){
 						String displayCommand = BakefileParser.expandVariables(command);
 
+						// Supprimer le tiret d'ignore-errors si présent dans displayCommand
+						if (ignoreErrors && displayCommand.trim().startsWith("-")) {
+							displayCommand = displayCommand.replaceFirst("\\s*-\\s*", " ").trim();
+						}
+					
 						// Afficher les lignes formatées avec traitement spécial pour les continuations
 						if (displayLines != null && !displayLines.isEmpty()) {
 							boolean isFirstLine = true;
@@ -126,16 +139,25 @@ public class CommandExecutor {
 									String expandedLine = line;
 									if (line.startsWith("\t")) {
 										String content = line.substring(1);
-										expandedLine = "\t" + BakefileParser.expandVariables(content);
-										System.out.println(expandedLine.substring(1));
+										expandedLine = BakefileParser.expandVariables(content);
 									} else {
 										expandedLine = BakefileParser.expandVariables(line);
-                    					System.out.println(expandedLine);
 									}
+
+									// Supprimer le tiret d'ignore-errors si présent
+									if (ignoreErrors && expandedLine.trim().startsWith("-")) {
+										expandedLine = expandedLine.replaceFirst("\\s*-\\s*", " ").trim();
+									}
+									System.out.println(expandedLine);
 									isFirstLine = false;
 								} else {
-									// Pour les lignes suivantes d'une continuation, conserver l'indentation
-									String expandedLine = BakefileParser.expandVariables(line);
+									// Pour les lignes suivantes d'une continuation, supprimer également l'indentation
+									String expandedLine = line;
+									if (line.startsWith("\t")) {
+										expandedLine = BakefileParser.expandVariables(line.substring(1));
+									} else {
+										expandedLine = BakefileParser.expandVariables(line);
+									}
 									System.out.println(expandedLine);
 								}
 							}