WinGetCLICommandResult.cs (2544B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="WinGetCLICommandResult.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.WinGet.Client.Engine.Helpers 8 { 9 using Microsoft.WinGet.Client.Engine.Exceptions; 10 11 /// <summary> 12 /// Winget cli command result. 13 /// </summary> 14 internal class WinGetCLICommandResult 15 { 16 /// <summary> 17 /// Initializes a new instance of the <see cref="WinGetCLICommandResult"/> class. 18 /// </summary> 19 /// <param name="command">Command.</param> 20 /// <param name="parameters">Parameters.</param> 21 /// <param name="exitCode">Exit code.</param> 22 /// <param name="stdOut">Standard output.</param> 23 /// <param name="stdErr">Standard error.</param> 24 public WinGetCLICommandResult(string command, string? parameters, int exitCode, string stdOut, string stdErr) 25 { 26 this.Command = command; 27 this.Parameters = parameters; 28 this.ExitCode = exitCode; 29 this.StdOut = stdOut; 30 this.StdErr = stdErr; 31 } 32 33 /// <summary> 34 /// Gets the command. 35 /// </summary> 36 public string Command { get; private set; } 37 38 /// <summary> 39 /// Gets the parameters. 40 /// </summary> 41 public string? Parameters { get; private set; } 42 43 /// <summary> 44 /// Gets the exit code. 45 /// </summary> 46 public int ExitCode { get; private set; } 47 48 /// <summary> 49 /// Gets the standard output. 50 /// </summary> 51 public string StdOut { get; private set; } 52 53 /// <summary> 54 /// Gets the standard error. 55 /// </summary> 56 public string StdErr { get; private set; } 57 58 /// <summary> 59 /// Verifies exit code. 60 /// </summary> 61 /// <param name="exitCode">Optional exit code.</param> 62 public void VerifyExitCode(int exitCode = 0) 63 { 64 if (this.ExitCode != exitCode) 65 { 66 throw new WinGetCLIException( 67 this.Command, 68 this.Parameters, 69 this.ExitCode, 70 this.StdOut, 71 this.StdErr); 72 } 73 } 74 } 75 }