diff --git a/src/nuget-cli/Program.cs b/src/nuget-cli/Program.cs index cfc0d39..7914c74 100644 --- a/src/nuget-cli/Program.cs +++ b/src/nuget-cli/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Mono.Options; using Newtonsoft.Json; @@ -12,12 +13,13 @@ namespace nuget_cli private static bool shouldShowPushHelp; private static string apiKey = null; private static string source = null; + private static int pushKO = 0; static Program() { } - static void Main(string[] args) + static int Main(string[] args) { var options = new OptionSet { @@ -85,6 +87,7 @@ namespace nuget_cli } List reports = await PushPkgAsync(pargs); Console.WriteLine(JsonConvert.SerializeObject(reports)); + pushKO = reports.Count( r => !r.OK ); } }; commandSet.Add(push); @@ -107,7 +110,7 @@ namespace nuget_cli Console.Write("nuget-cli: "); Console.WriteLine(e.Message); Console.WriteLine("Try `nuget-cli --help' for more information."); - return; + return 2; } @@ -116,11 +119,14 @@ namespace nuget_cli // output the options Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); - return; + return 1; } + + int runCode = commandSet.Run(args); + if (runCode == 0 ) if (pushKO>0) return 3; - - commandSet.Run(args); + return runCode; + } } } diff --git a/src/nuget-cli/PushCommand.cs b/src/nuget-cli/PushCommand.cs index b680bc5..74aadb7 100644 --- a/src/nuget-cli/PushCommand.cs +++ b/src/nuget-cli/PushCommand.cs @@ -18,7 +18,6 @@ namespace nuget_cli }; if (!fi.Exists) { - report.StatusCode = "local"; report.Message = "Le fichier n'existe pas"; return report; } @@ -37,6 +36,7 @@ namespace nuget_cli { await Console.Error.WriteLineAsync(ex.Message); report.StatusCode = ex.Status.ToString(); + report.OK = false; using (var respStream = ex.Response.GetResponseStream()) { StreamReader sr = new StreamReader(respStream); diff --git a/src/nuget-cli/PushReport.cs b/src/nuget-cli/PushReport.cs index 96df93d..4d316d8 100644 --- a/src/nuget-cli/PushReport.cs +++ b/src/nuget-cli/PushReport.cs @@ -1,9 +1,12 @@ +using System.Net; + namespace nuget_cli { public class PushReport { public string PkgName { get; set; } public bool Executed { get; internal set; } + public bool OK { get; internal set; } public bool AlreadyPresent { get; internal set; } public string Message { get; internal set; } public string StatusCode { get; internal set; } diff --git a/src/nuget-cli/UploadFilesToServerUsingHttpClient.cs b/src/nuget-cli/UploadFilesToServerUsingHttpClient.cs index 8ff8c6a..8ebdab4 100644 --- a/src/nuget-cli/UploadFilesToServerUsingHttpClient.cs +++ b/src/nuget-cli/UploadFilesToServerUsingHttpClient.cs @@ -60,6 +60,7 @@ namespace nuget_cli { report.Message = rex.Message; report.StatusCode = "internal error"; + report.OK = false; Console.Error.WriteLine(rex.Message); } } diff --git a/src/nuget-cli/UploadFilesToServerUsingWebRequest.cs b/src/nuget-cli/UploadFilesToServerUsingWebRequest.cs index ba7b540..ffbb512 100644 --- a/src/nuget-cli/UploadFilesToServerUsingWebRequest.cs +++ b/src/nuget-cli/UploadFilesToServerUsingWebRequest.cs @@ -83,7 +83,10 @@ namespace nuget_cli { String json = re.ReadToEnd(); report.Message = json; - report.StatusCode = (resp as HttpWebResponse).StatusCode.ToString(); + var hrep = resp as HttpWebResponse; + report.StatusCode = hrep.StatusCode.ToString(); + report.OK = hrep.StatusCode == + HttpStatusCode.Accepted || hrep.StatusCode == HttpStatusCode.OK; } else throw new Exception("Invalid server response type"); }