refact
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ src/nuget-host/bin/
|
|||||||
src/nuget-host/obj/
|
src/nuget-host/obj/
|
||||||
src/nuget-cli/obj
|
src/nuget-cli/obj
|
||||||
src/nuget-cli/bin
|
src/nuget-cli/bin
|
||||||
|
.vscode/launch.json
|
||||||
|
src/nuget-cli/.vscode/
|
||||||
|
51
.vscode/launch.json
vendored
51
.vscode/launch.json
vendored
@ -1,51 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": ".NET Core Launch (web)",
|
|
||||||
"type": "coreclr",
|
|
||||||
"request": "launch",
|
|
||||||
"preLaunchTask": "build",
|
|
||||||
"program": "${workspaceFolder}/src/nuget-host/bin/Debug/netcoreapp2.1/nuget-host.dll",
|
|
||||||
"args": [],
|
|
||||||
"cwd": "${workspaceFolder}/src/nuget-host",
|
|
||||||
"stopAtEntry": false,
|
|
||||||
"requireExactSource": false,
|
|
||||||
"serverReadyAction": {
|
|
||||||
"action": "openExternally",
|
|
||||||
"pattern": "\\\\bNow listening on:\\\\s+(https?://\\\\S+)"
|
|
||||||
},
|
|
||||||
"env": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
},
|
|
||||||
"sourceFileMap": {
|
|
||||||
"/Views": "${workspaceFolder}/src/nuget-host/Views"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": ".NET Core Launch cli",
|
|
||||||
"type": "coreclr",
|
|
||||||
"request": "launch",
|
|
||||||
"preLaunchTask": "buildcli",
|
|
||||||
"program": "${workspaceFolder}/src/nuget-cli/bin/Debug/netcoreapp2.1/nuget-cli.dll",
|
|
||||||
"args": [ "push",
|
|
||||||
"-k", "lame-aki-key",
|
|
||||||
"-s", "http://localhost:5000/packages",
|
|
||||||
"lame.nupkg"
|
|
||||||
],
|
|
||||||
"cwd": "${workspaceFolder}/src/nuget-cli",
|
|
||||||
"stopAtEntry": false,
|
|
||||||
"requireExactSource": false,
|
|
||||||
"serverReadyAction": {
|
|
||||||
"action": "openExternally",
|
|
||||||
"pattern": "\\\\bNow listening on:\\\\s+(https?://\\\\S+)"
|
|
||||||
},
|
|
||||||
"env": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace nuget_cli
|
namespace nuget_cli
|
||||||
{
|
{
|
||||||
@ -21,12 +22,17 @@ namespace nuget_cli
|
|||||||
throw new NotImplementedException();
|
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)
|
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)
|
private static object StoreApiKey(IEnumerable<string> str)
|
||||||
|
@ -67,8 +67,7 @@ namespace nuget_cli
|
|||||||
|
|
||||||
var push = new Command("push")
|
var push = new Command("push")
|
||||||
{
|
{
|
||||||
|
Run = async sargs =>
|
||||||
Run = sargs =>
|
|
||||||
{
|
{
|
||||||
var pargs = pushoptions.Parse(sargs);
|
var pargs = pushoptions.Parse(sargs);
|
||||||
if (shouldShowPushHelp)
|
if (shouldShowPushHelp)
|
||||||
@ -78,7 +77,7 @@ namespace nuget_cli
|
|||||||
pushoptions.WriteOptionDescriptions(Console.Out);
|
pushoptions.WriteOptionDescriptions(Console.Out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PushPkg(pargs);
|
await PushPkgAsync(pargs);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
commandSet.Add(push);
|
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