22using System . Collections . Generic ;
33using Calamari . Common . Features . Processes ;
44using Calamari . Common . Plumbing . Logging ;
5+ using Calamari . Common . Plumbing . Variables ;
56
67namespace Calamari . Kubernetes . Integration
78{
@@ -10,23 +11,31 @@ public class CommandLineTool
1011 protected readonly ILog log ;
1112 protected string workingDirectory ;
1213 protected Dictionary < string , string > environmentVars ;
14+ protected readonly IVariables variables ;
1315
1416 readonly ICommandLineRunner commandLineRunner ;
1517
1618 protected CommandLineTool (
1719 ILog log ,
1820 ICommandLineRunner commandLineRunner ,
1921 string workingDirectory ,
20- Dictionary < string , string > environmentVars )
22+ Dictionary < string , string > environmentVars ,
23+ IVariables variables )
2124 {
2225 this . log = log ;
2326 this . commandLineRunner = commandLineRunner ;
2427 this . workingDirectory = workingDirectory ;
2528 this . environmentVars = environmentVars ;
29+ this . variables = variables ;
2630 }
2731
2832 public string ExecutableLocation { get ; protected set ; }
2933
34+ protected virtual bool ShouldLogSuccessfulOutputAsInfo ( )
35+ {
36+ return variables . GetFlag ( SpecialVariables . LogCliOutputAsInfo ) ;
37+ }
38+
3039 protected CommandResult ExecuteCommandAndLogOutput ( CommandLineInvocation invocation )
3140 => ExecuteCommandAndLogOutput ( invocation , false ) ;
3241
@@ -52,7 +61,8 @@ CommandResult ExecuteCommandAndLogOutput(CommandLineInvocation invocation, bool
5261
5362 var result = commandLineRunner . Execute ( invocation ) ;
5463
55- LogCapturedOutput ( result , captureCommandOutput , logOutputAsVerbose ) ;
64+ var logSuccessAsInfo = ShouldLogSuccessfulOutputAsInfo ( ) ;
65+ LogCapturedOutput ( result , captureCommandOutput , logOutputAsVerbose , logSuccessAsInfo ) ;
5666
5767 return result ;
5868 }
@@ -62,13 +72,21 @@ void LogCommandText(CommandLineInvocation invocation)
6272 log . Verbose ( invocation . ToString ( ) ) ;
6373 }
6474
65- void LogCapturedOutput ( CommandResult result , CaptureCommandOutput captureCommandOutput , bool logOutputAsVerbose )
75+ void LogCapturedOutput ( CommandResult result , CaptureCommandOutput captureCommandOutput , bool logOutputAsVerbose , bool logSuccessAsInfo )
6676 {
6777 foreach ( var message in captureCommandOutput . Messages )
6878 {
6979 if ( result . ExitCode == 0 )
7080 {
71- log . Verbose ( message . Text ) ;
81+ // When logSuccessAsInfo is true, log successful output at Info level
82+ if ( logSuccessAsInfo )
83+ {
84+ log . Info ( message . Text ) ;
85+ }
86+ else
87+ {
88+ log . Verbose ( message . Text ) ;
89+ }
7290 continue ;
7391 }
7492
0 commit comments