public static int Main(string[] args) { var theCmdLineDefinition = new CmdLineDefinition { Name = "epos-auth", Subcommands = { DefaultCommand.Instance, }, HasDifferentiatedSubcommands = false }; return(theCmdLineDefinition.Try(args)); }
public static int Execute(Options options, CmdLineDefinition definition) { Console.WriteLine("Service URL: " + options.WebApiUrl); Console.WriteLine("Text color: " + options.TextColor); Console.WriteLine(); Console.WriteLine("Please enter a snippet of LaTeX and finish with [Ctrl+Z][Enter]."); using var theClient = new HttpClient(); string theLaTeX = Console.In.ReadToEnd(); var theRequest = new LaTeXServiceRequest { LaTeX = theLaTeX, TextColor = options.TextColor, PageColor = "000000" }; string theJson = JsonSerializer.Serialize( theRequest, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase } ); string theBase64UrlJson = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(theJson)); byte[] theBytes = theClient.GetByteArrayAsync($"{options.WebApiUrl}/{theBase64UrlJson}").Result; string thePngFilename = Path.GetTempFileName() + ".png"; File.WriteAllBytes(thePngFilename, theBytes); using var theProcess = new Process { StartInfo = new ProcessStartInfo(thePngFilename) { UseShellExecute = true } }; theProcess.Start(); return(0); }
public static int Main(string[] args) { var theCmdLineDefinition = new CmdLineDefinition { Name = "sample", // <- if null, .exe-Filename is taken Subcommands = { new CmdLineSubcommand <BuildOptions>("build", "Builds something.") { Options = { new CmdLineOption <int>('p', "Sets the project number.") { LongName = "project-number" }, new CmdLineOption <string>('m', "Sets the used memory.") { LongName = "memory", DefaultValue = "1 GB" }, new CmdLineSwitch('d', "Disables the command."), new CmdLineSwitch('z', "Zzzz...") }, Parameters = { new CmdLineParameter <string>("filename", "Sets the filename.") }, CmdLineFunc = (options, definition) => { // Do something for the build subcommand // ... Console.WriteLine("sample command line application" + Lf); Console.WriteLine(options.Dump() + Lf); return(0); // <- your error code or 0, if successful } }, new CmdLineSubcommand <TestOptions>("test", "Tests something.") { Options = { new CmdLineSwitch('h', "Shows help for this subcommand.") { LongName = "help" } }, CmdLineFunc = (options, definition) => { if (options.ShowHelp) { definition.ShowHelp("test"); } else { Console.WriteLine("sample command line application" + Lf); Console.WriteLine("Subcommand test was invoked." + Lf); } return(0); } } } }; return(theCmdLineDefinition.Try(args)); }