diff --git a/.gitignore b/.gitignore index 98a1265..98f8ad7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ test/nuget.host.tests/bin/ test/nuget.host.tests/obj src/nuget-host/bin/ src/nuget-host/obj/ +src/nuget-cli/obj +src/nuget-cli/bin diff --git a/.vscode/launch.json b/.vscode/launch.json index d2897b2..561ea13 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,6 +24,28 @@ "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/.vscode/tasks.json b/.vscode/tasks.json index 776c976..cd12d2f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -19,6 +19,21 @@ "type": "process", "args": [ "build", + "src/nuget-host", + "/p:Configuration=Debug", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary", + "--ignore-failed-sources" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "buildcli", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "src/nuget-cli", "/p:Configuration=Debug", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary", diff --git a/src/nuget-cli/Program.Commands.cs b/src/nuget-cli/Program.Commands.cs new file mode 100644 index 0000000..d648f45 --- /dev/null +++ b/src/nuget-cli/Program.Commands.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + +namespace nuget_cli +{ + partial class Program + { + + private static void SourceList(IEnumerable sargs) + { + throw new NotImplementedException(); + } + + private static object SourceAdd(IEnumerable str) + { + throw new NotImplementedException(); + } + + private static object Add(IEnumerable str) + { + throw new NotImplementedException(); + } + + private static object PushPkg(IEnumerable pkg) + { + throw new NotImplementedException(); + } + + private static object StoreApiKey(IEnumerable str) + { + throw new NotImplementedException(); + } + + private static string LocalizeThis(string arg) + { + return arg; + } + } +} \ No newline at end of file diff --git a/src/nuget-cli/Program.cs b/src/nuget-cli/Program.cs new file mode 100644 index 0000000..1077bd9 --- /dev/null +++ b/src/nuget-cli/Program.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using Mono.Options; + +namespace nuget_cli +{ + partial class Program + { + private static bool shouldShowHelp; + private static bool shouldShowSourceHelp; + private static bool shouldShowPushHelp; + private static string apiKey = null; + private static string source = null; + + static void Main(string[] args) + { + + var options = new OptionSet { + { "h|help", "show this message and exit", h => shouldShowHelp = h != null }, + }; + var pushoptions = new OptionSet { + { "k|api-key=", "use api key", val => apiKey = apiKey ?? val }, + { "s|source=", "use source", val => source = source ?? val }, + { "h|help", "show this message and exit", h => shouldShowPushHelp = h != null }, + }; + var sourceoptions = new OptionSet { + { "h|help", "show this message and exit", h => shouldShowSourceHelp = h != null }, + }; + + var commandSet = new CommandSet("yaget-cli"); + + + var srclst = new Command("list") + { + Run = sargs => SourceList(sargs) + }; + var srcadd = new Command("add") + { + Run = sargs => SourceAdd(sargs) + }; + var srcCmd = new Command("source") + { + Run = sargs => + { + var pargs = sourceoptions.Parse(sargs); + if (shouldShowSourceHelp) + { + // output the options + Console.WriteLine("Push Options:"); + sourceoptions.WriteOptionDescriptions(Console.Out); + return; + } + } + }; + + var sourceCmdSet = new CommandSet("source") + { + srclst, + srcadd + }; + + var add = new Command("add") + { + Run = sargs => Add(sargs) + }; + commandSet.Add(add); + + var push = new Command("push") + { + + Run = sargs => + { + var pargs = pushoptions.Parse(sargs); + if (shouldShowPushHelp) + { + // output the options + Console.WriteLine("Push Options:"); + pushoptions.WriteOptionDescriptions(Console.Out); + return; + } + PushPkg(pargs); + } + }; + commandSet.Add(push); + var setapikey = new Command("set-api-key") + { + Run = sargs => StoreApiKey(sargs) + }; + commandSet.Add(setapikey); + + + List extra; + try + { + // parse the command line + extra = options.Parse(args); + } + catch (OptionException e) + { + // output some error message + Console.Write("nuget-cli: "); + Console.WriteLine(e.Message); + Console.WriteLine("Try `nuget-cli --help' for more information."); + return; + } + + + if (shouldShowHelp) + { + // output the options + Console.WriteLine("Options:"); + options.WriteOptionDescriptions(Console.Out); + return; + } + + commandSet.Run(args); + } + } +} diff --git a/src/nuget-cli/nuget-cli.csproj b/src/nuget-cli/nuget-cli.csproj new file mode 100644 index 0000000..fc7487f --- /dev/null +++ b/src/nuget-cli/nuget-cli.csproj @@ -0,0 +1,11 @@ + + + + Exe + netcoreapp2.1 + nuget_cli + + + + +