static void Main(string[] args) { var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication { Name = "VSS C# Project Tool", Description = "A tool to help with parsing a collection of C# projects, and filtering based on the contents." }; app.HelpOption("-?|-h|--help"); var directories = app.Option("-d|--directory", "Directories to search (allows multiple)", CommandOptionType.MultipleValue); var isRecursive = app.Option("-r|--recursive", "Recursive search, defaults to false", CommandOptionType.NoValue); app.OnExecute(() => { app.ShowHelp(); return(1); }); TagsCommand(app, directories, isRecursive); ReferencesCommand(app, directories, isRecursive); app.Execute(args); }
static int Main(string[] args) { var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication(); var cert = app.Option("--cert", "cert file", CommandOptionType.SingleValue); var coreDll = app.Option("--core", "path to core dll", CommandOptionType.SingleValue); bool certExists() { return(File.Exists(cert.Value())); } bool coreExists() { return(File.Exists(coreDll.Value())); } bool verifyTopOptions() { return(!string.IsNullOrWhiteSpace(cert.Value()) && !string.IsNullOrWhiteSpace(coreDll.Value()) && certExists() && coreExists()); } app.Command("interactive", config => { string buff = "", licensetype = "", name = "", email = "", businessname = ""; bool valid_guid = false, valid_installid = false; Guid guid = new Guid(), installid = new Guid(); config.OnExecute(() => { if (!verifyTopOptions()) { if (!coreExists()) { config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}"); } if (!certExists()) { config.Error.WriteLine($"Cant find certificate at: {cert.Value()}"); } config.ShowHelp(); return(1); } WriteLine("Interactive license mode..."); while (licensetype == "") { WriteLine("What would you like to generate, a [u]ser license or an [o]rg license?"); buff = Console.ReadLine(); if (buff == "u") { licensetype = "user"; WriteLineOver("Okay, we will generate a user license."); while (valid_guid == false) { WriteLine("Please provide the user's guid — refer to the Readme for details on how to retrieve this. [GUID]:"); buff = Console.ReadLine(); if (Guid.TryParse(buff, out guid)) { valid_guid = true; } else { WriteLineOver("The user-guid provided does not appear to be valid."); } } } else if (buff == "o") { licensetype = "org"; WriteLineOver("Okay, we will generate an organization license."); while (valid_installid == false) { WriteLine("Please provide your Bitwarden Install-ID — refer to the Readme for details on how to retrieve this. [Install-ID]:"); buff = Console.ReadLine(); if (Guid.TryParse(buff, out installid)) { valid_installid = true; } else { WriteLineOver("The install-id provided does not appear to be valid."); } } while (businessname == "") { WriteLineOver("Please enter a business name, default is BitBetter. [Business Name]:"); buff = Console.ReadLine(); if (buff == "") { businessname = "BitBetter"; } else if (checkBusinessName(buff)) { businessname = buff; } } } else { WriteLineOver("Unrecognized option \'" + buff + "\'. "); } } while (name == "") { WriteLineOver("Please provide the username this license will be registered to. [username]:"); buff = Console.ReadLine(); if (checkUsername(buff)) { name = buff; } } while (email == "") { WriteLineOver("Please provide the email address for the user " + name + ". [email]"); buff = Console.ReadLine(); if (checkEmail(buff)) { email = buff; } } if (licensetype == "user") { WriteLineOver("Confirm creation of \"user\" license for username: \"" + name + "\", email: \"" + email + "\", User-GUID: \"" + guid + "\"? Y/n"); buff = Console.ReadLine(); if (buff == "" || buff == "y" || buff == "Y") { GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, guid, null); } else { WriteLineOver("Exiting..."); return(0); } } else if (licensetype == "org") { WriteLineOver("Confirm creation of \"organization\" license for business name: \"" + businessname + "\", username: \"" + name + "\", email: \"" + email + "\", Install-ID: \"" + installid + "\"? Y/n"); buff = Console.ReadLine(); if (buff == "" || buff == "y" || buff == "Y") { GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, installid, businessname, null); } else { WriteLineOver("Exiting..."); return(0); } } return(0); }); }); app.Command("user", config => { var name = config.Argument("Name", "your name"); var email = config.Argument("Email", "your email"); var userIdArg = config.Argument("User ID", "your user id"); var key = config.Argument("Key", "your key id (optional)"); var help = config.HelpOption("--help | -h | -?"); config.OnExecute(() => { if (!verifyTopOptions()) { if (!coreExists()) { config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}"); } if (!certExists()) { config.Error.WriteLine($"Cant find certificate at: {cert.Value()}"); } config.ShowHelp(); return(1); } else if (string.IsNullOrWhiteSpace(name.Value) || string.IsNullOrWhiteSpace(email.Value)) { config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}'"); config.ShowHelp("user"); return(1); } if (string.IsNullOrWhiteSpace(userIdArg.Value) || !Guid.TryParse(userIdArg.Value, out Guid userId)) { config.Error.WriteLine($"User ID not provided"); config.ShowHelp("user"); return(1); } GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, userId, key.Value); return(0); }); }); app.Command("org", config => { var name = config.Argument("Name", "your name"); var email = config.Argument("Email", "your email"); var installId = config.Argument("InstallId", "your installation id (GUID)"); var businessName = config.Argument("BusinessName", "name For the organization (optional)"); var key = config.Argument("Key", "your key id (optional)"); var help = config.HelpOption("--help | -h | -?"); config.OnExecute(() => { if (!verifyTopOptions()) { if (!coreExists()) { config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}"); } if (!certExists()) { config.Error.WriteLine($"Cant find certificate at: {cert.Value()}"); } config.ShowHelp(); return(1); } else if (string.IsNullOrWhiteSpace(name.Value) || string.IsNullOrWhiteSpace(email.Value) || string.IsNullOrWhiteSpace(installId.Value)) { config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}' InstallId='{installId.Value}'"); config.ShowHelp("org"); return(1); } if (!Guid.TryParse(installId.Value, out Guid installationId)) { config.Error.WriteLine("Unable to parse your installation id as a GUID"); config.Error.WriteLine($"Here's a new guid: {Guid.NewGuid()}"); config.ShowHelp("org"); return(1); } GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, installationId, businessName.Value, key.Value); return(0); }); }); app.OnExecute(() => { app.ShowHelp(); return(10); }); app.HelpOption("-? | -h | --help"); try { return(app.Execute(args)); } catch (Exception e) { Console.Error.WriteLine("Oops: {0}", e); return(100); } }
static int Main(string[] args) { var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication(); var cert = app.Option("--cert", "cert file", CommandOptionType.SingleValue); var coreDll = app.Option("--core", "path to core dll", CommandOptionType.SingleValue); bool certExists() { return(File.Exists(cert.Value())); } bool coreExists() { return(File.Exists(coreDll.Value())); } bool verifyTopOptions() { return(!string.IsNullOrWhiteSpace(cert.Value()) && !string.IsNullOrWhiteSpace(coreDll.Value()) && certExists() && coreExists()); } app.Command("user", config => { var name = config.Argument("Name", "your name"); var email = config.Argument("Email", "your email"); var userIdArg = config.Argument("User ID", "your user id"); var key = config.Argument("Key", "your key id (optional)"); var help = config.HelpOption("--help | -h | -?"); config.OnExecute(() => { if (!verifyTopOptions()) { if (!coreExists()) { config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}"); } if (!certExists()) { config.Error.WriteLine($"Cant find certificate at: {cert.Value()}"); } config.ShowHelp(); return(1); } else if (string.IsNullOrWhiteSpace(name.Value) || string.IsNullOrWhiteSpace(email.Value)) { config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}'"); config.ShowHelp("user"); return(1); } if (string.IsNullOrWhiteSpace(userIdArg.Value) || !Guid.TryParse(userIdArg.Value, out Guid userId)) { config.Error.WriteLine($"User ID not provided"); config.ShowHelp("user"); return(1); } GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, userId, key.Value); return(0); }); }); app.Command("org", config => { var name = config.Argument("Name", "your name"); var email = config.Argument("Email", "your email"); var installId = config.Argument("InstallId", "your installation id (GUID)"); var key = config.Argument("Key", "your key id (optional)"); var help = config.HelpOption("--help | -h | -?"); config.OnExecute(() => { if (!verifyTopOptions()) { if (!coreExists()) { config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}"); } if (!certExists()) { config.Error.WriteLine($"Cant find certificate at: {cert.Value()}"); } config.ShowHelp(); return(1); } else if (string.IsNullOrWhiteSpace(name.Value) || string.IsNullOrWhiteSpace(email.Value) || string.IsNullOrWhiteSpace(installId.Value)) { config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}' InstallId='{installId.Value}'"); config.ShowHelp("org"); return(1); } if (!Guid.TryParse(installId.Value, out Guid installationId)) { config.Error.WriteLine("Unable to parse your installation id as a GUID"); config.Error.WriteLine($"Here's a new guid: {Guid.NewGuid()}"); config.ShowHelp("org"); return(1); } GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, installationId, key.Value); return(0); }); }); app.OnExecute(() => { app.ShowHelp(); return(10); }); app.HelpOption("-? | -h | --help"); try { return(app.Execute(args)); } catch (Exception e) { Console.Error.WriteLine("Oops: {0}", e); return(100); } }