This commit is contained in:
Paul Schneider
2021-05-10 23:03:59 +01:00
parent 36e1137e50
commit b6098c28a6
6 changed files with 53 additions and 56 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace nuget_cli
{
@ -21,12 +22,17 @@ namespace nuget_cli
throw new NotImplementedException();
}
private static object PushPkg(IEnumerable<string> pkgs)
private static async Task<List<PushReport>> PushPkgAsync(IEnumerable<string> pkgs)
{
List<PushReport> pushReports = new List<PushReport>();
foreach (string pkg in pkgs)
{
var report = await PushCommand.RunAsync(pkg,source,apiKey);
pushReports.Add(report);
}
return pushReports;
}
private static object StoreApiKey(IEnumerable<string> str)

View File

@ -67,8 +67,7 @@ namespace nuget_cli
var push = new Command("push")
{
Run = sargs =>
Run = async sargs =>
{
var pargs = pushoptions.Parse(sargs);
if (shouldShowPushHelp)
@ -78,7 +77,7 @@ namespace nuget_cli
pushoptions.WriteOptionDescriptions(Console.Out);
return;
}
PushPkg(pargs);
await PushPkgAsync(pargs);
}
};
commandSet.Add(push);

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace nuget_cli
{
internal class PushCommand
{
static internal async Task<PushReport> RunAsync(string pkg, string source, string apikey)
{
var report = new PushReport {
PkgName = pkg
};
FileInfo fi = new FileInfo(pkg);
if (!fi.Exists)
throw new Exception("Le fichier n'existe pas");
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("api-key", apikey);
client.BaseAddress = new Uri(source);
var content = new StreamContent(fi.OpenRead());
var response = await client.PutAsync(source, content);
report.StatusCode = response.StatusCode.ToString();
report.Message = await response.Content.ReadAsStringAsync();
report.Executed = true;
return report;
}
}
}

View File

@ -0,0 +1,11 @@
namespace nuget_cli
{
internal class PushReport
{
internal string PkgName { get; set; }
internal bool Executed { get; set; }
internal bool AlreadyPresent { get; set; }
internal string Message { get; set; }
internal string StatusCode { get; set; }
}
}