report.OK

broken/ef
Paul Schneider 3 years ago
parent 54a900c361
commit 9575dd2754
5 changed files with 20 additions and 7 deletions

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Mono.Options; using Mono.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -12,12 +13,13 @@ namespace nuget_cli
private static bool shouldShowPushHelp; private static bool shouldShowPushHelp;
private static string apiKey = null; private static string apiKey = null;
private static string source = null; private static string source = null;
private static int pushKO = 0;
static Program() static Program()
{ {
} }
static void Main(string[] args) static int Main(string[] args)
{ {
var options = new OptionSet { var options = new OptionSet {
@ -85,6 +87,7 @@ namespace nuget_cli
} }
List<PushReport> reports = await PushPkgAsync(pargs); List<PushReport> reports = await PushPkgAsync(pargs);
Console.WriteLine(JsonConvert.SerializeObject(reports)); Console.WriteLine(JsonConvert.SerializeObject(reports));
pushKO = reports.Count( r => !r.OK );
} }
}; };
commandSet.Add(push); commandSet.Add(push);
@ -107,7 +110,7 @@ namespace nuget_cli
Console.Write("nuget-cli: "); Console.Write("nuget-cli: ");
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
Console.WriteLine("Try `nuget-cli --help' for more information."); Console.WriteLine("Try `nuget-cli --help' for more information.");
return; return 2;
} }
@ -116,11 +119,14 @@ namespace nuget_cli
// output the options // output the options
Console.WriteLine("Options:"); Console.WriteLine("Options:");
options.WriteOptionDescriptions(Console.Out); options.WriteOptionDescriptions(Console.Out);
return; return 1;
} }
int runCode = commandSet.Run(args);
if (runCode == 0 ) if (pushKO>0) return 3;
return runCode;
commandSet.Run(args);
} }
} }
} }

@ -18,7 +18,6 @@ namespace nuget_cli
}; };
if (!fi.Exists) if (!fi.Exists)
{ {
report.StatusCode = "local";
report.Message = "Le fichier n'existe pas"; report.Message = "Le fichier n'existe pas";
return report; return report;
} }
@ -37,6 +36,7 @@ namespace nuget_cli
{ {
await Console.Error.WriteLineAsync(ex.Message); await Console.Error.WriteLineAsync(ex.Message);
report.StatusCode = ex.Status.ToString(); report.StatusCode = ex.Status.ToString();
report.OK = false;
using (var respStream = ex.Response.GetResponseStream()) using (var respStream = ex.Response.GetResponseStream())
{ {
StreamReader sr = new StreamReader(respStream); StreamReader sr = new StreamReader(respStream);

@ -1,9 +1,12 @@
using System.Net;
namespace nuget_cli namespace nuget_cli
{ {
public class PushReport public class PushReport
{ {
public string PkgName { get; set; } public string PkgName { get; set; }
public bool Executed { get; internal set; } public bool Executed { get; internal set; }
public bool OK { get; internal set; }
public bool AlreadyPresent { get; internal set; } public bool AlreadyPresent { get; internal set; }
public string Message { get; internal set; } public string Message { get; internal set; }
public string StatusCode { get; internal set; } public string StatusCode { get; internal set; }

@ -60,6 +60,7 @@ namespace nuget_cli
{ {
report.Message = rex.Message; report.Message = rex.Message;
report.StatusCode = "internal error"; report.StatusCode = "internal error";
report.OK = false;
Console.Error.WriteLine(rex.Message); Console.Error.WriteLine(rex.Message);
} }
} }

@ -83,7 +83,10 @@ namespace nuget_cli
{ {
String json = re.ReadToEnd(); String json = re.ReadToEnd();
report.Message = json; 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"); else throw new Exception("Invalid server response type");
} }

Loading…