CommandResult ExecuteCommandInternal(string[] arguments, out string result, bool outputToCalamariConsole) { var environmentVar = defaultEnvironmentVariables; if (environmentVariables != null) { environmentVar.AddRange(environmentVariables); } var terraformExecutable = variables.Get(TerraformSpecialVariables.Action.Terraform.CustomTerraformExecutable) ?? $"terraform{(CalamariEnvironment.IsRunningOnWindows ? ".exe" : string.Empty)}"; var captureOutput = new CaptureInvocationOutputSink(); var commandLineInvocation = new CommandLineInvocation(terraformExecutable, arguments) { WorkingDirectory = templateDirectory, EnvironmentVars = environmentVar, OutputToLog = outputToCalamariConsole, AdditionalInvocationOutputSink = captureOutput }; log.Info(commandLineInvocation.ToString()); var commandResult = commandLineRunner.Execute(commandLineInvocation); result = string.Join("\n", captureOutput.Infos); return(commandResult); }
public CommandResult Execute(CommandLineInvocation invocation) { // We only want to output executable string. eg. ExecuteCommandAndReturnOutput("where", "kubectl.exe") if (new string[] { "kubectl", "az", "gcloud", "kubectl.exe", "az.cmd", "gcloud.cmd" }.Contains(invocation.Arguments)) { invocation.AdditionalInvocationOutputSink?.WriteInfo(Path.GetFileNameWithoutExtension(invocation.Arguments)); } return(new CommandResult(invocation.ToString(), 0)); }
CommandResult ExecuteCommand(CommandLineInvocation invocation) { invocation.EnvironmentVars = environmentVars; invocation.WorkingDirectory = workingDirectory; invocation.OutputAsVerbose = false; invocation.OutputToLog = false; var captureCommandOutput = new CaptureCommandOutput(); invocation.AdditionalInvocationOutputSink = captureCommandOutput; var commandString = invocation.ToString(); commandString = redactMap.Aggregate(commandString, (current, pair) => current.Replace(pair.Key, pair.Value)); log.Verbose(commandString); var result = commandLineRunner.Execute(invocation); foreach (var message in captureCommandOutput.Messages) { if (result.ExitCode == 0) { log.Verbose(message.Text); continue; } switch (message.Level) { case Level.Info: log.Verbose(message.Text); break; case Level.Error: log.Error(message.Text); break; } } return(result); }
/// <summary> /// This is a special case for when the invocation results in an error /// 1) but is to be expected as a valid scenario; and /// 2) we don't want to inform this at an error level when this happens. /// </summary> /// <param name="invocation"></param> /// <returns></returns> CommandResult ExecuteCommandWithVerboseLoggingOnly(CommandLineInvocation invocation) { invocation.EnvironmentVars = environmentVars; invocation.WorkingDirectory = workingDirectory; invocation.OutputAsVerbose = true; invocation.OutputToLog = false; var captureCommandOutput = new CaptureCommandOutput(); invocation.AdditionalInvocationOutputSink = captureCommandOutput; var commandString = invocation.ToString(); commandString = redactMap.Aggregate(commandString, (current, pair) => current.Replace(pair.Key, pair.Value)); log.Verbose(commandString); var result = commandLineRunner.Execute(invocation); captureCommandOutput.Messages.ForEach(message => log.Verbose(message.Text)); return(result); }
CommandResult ExecuteCommandInternal(string arguments, out string result, ICommandOutput output = null) { var environmentVar = defaultEnvironmentVariables; if (environmentVariables != null) { environmentVar.MergeDictionaries(environmentVariables); } var commandLineInvocation = new CommandLineInvocation(TerraformExecutable, arguments, TemplateDirectory, environmentVar); var commandOutput = new CaptureOutput(output ?? new ConsoleCommandOutput()); var cmd = new CommandLineRunner(commandOutput); Log.Info(commandLineInvocation.ToString()); var commandResult = cmd.Execute(commandLineInvocation); result = String.Join("\n", commandOutput.Infos); return(commandResult); }