This commit is contained in:
Paul Schneider
2021-05-10 21:32:29 +01:00
parent 4cec5d0229
commit 3086cc65c4
6 changed files with 208 additions and 0 deletions

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
namespace nuget_cli
{
partial class Program
{
private static void SourceList(IEnumerable<string> sargs)
{
throw new NotImplementedException();
}
private static object SourceAdd(IEnumerable<string> str)
{
throw new NotImplementedException();
}
private static object Add(IEnumerable<string> str)
{
throw new NotImplementedException();
}
private static object PushPkg(IEnumerable<string> pkg)
{
throw new NotImplementedException();
}
private static object StoreApiKey(IEnumerable<string> str)
{
throw new NotImplementedException();
}
private static string LocalizeThis(string arg)
{
return arg;
}
}
}

119
src/nuget-cli/Program.cs Normal file
View File

@ -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<string> 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);
}
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>nuget_cli</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mono.Options" Version="5.3.0" />
</ItemGroup>
</Project>