refact
This commit is contained in:
@ -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)
|
||||
|
@ -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);
|
||||
|
30
src/nuget-cli/PushCommand.cs
Normal file
30
src/nuget-cli/PushCommand.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
11
src/nuget-cli/PushReport.cs
Normal file
11
src/nuget-cli/PushReport.cs
Normal 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; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user