diff --git a/.gitignore b/.gitignore index 98f8ad7..9cbb5dd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ src/nuget-host/bin/ src/nuget-host/obj/ src/nuget-cli/obj src/nuget-cli/bin +.vscode/launch.json +src/nuget-cli/.vscode/ diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 561ea13..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -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" - } - } - ] -} \ No newline at end of file diff --git a/src/nuget-cli/Program.Commands.cs b/src/nuget-cli/Program.Commands.cs index 6861bc7..a79c892 100644 --- a/src/nuget-cli/Program.Commands.cs +++ b/src/nuget-cli/Program.Commands.cs @@ -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 pkgs) + private static async Task> PushPkgAsync(IEnumerable pkgs) { + List pushReports = new List(); + foreach (string pkg in pkgs) { - + var report = await PushCommand.RunAsync(pkg,source,apiKey); + + pushReports.Add(report); } + return pushReports; } private static object StoreApiKey(IEnumerable str) diff --git a/src/nuget-cli/Program.cs b/src/nuget-cli/Program.cs index 1077bd9..0fcc481 100644 --- a/src/nuget-cli/Program.cs +++ b/src/nuget-cli/Program.cs @@ -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); diff --git a/src/nuget-cli/PushCommand.cs b/src/nuget-cli/PushCommand.cs new file mode 100644 index 0000000..e5e4ae9 --- /dev/null +++ b/src/nuget-cli/PushCommand.cs @@ -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 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; + } + } +} \ No newline at end of file diff --git a/src/nuget-cli/PushReport.cs b/src/nuget-cli/PushReport.cs new file mode 100644 index 0000000..d4062fd --- /dev/null +++ b/src/nuget-cli/PushReport.cs @@ -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; } + } +} \ No newline at end of file